NSAttributedString strikethrough doesn't work with multi-line UILabel

Originator:SaagarJha28
Number:rdar://31174934 Date Originated:21-Mar-2017 11:08 AM
Status:Duplicate of 31127491 Resolved:
Product:iOS + SDK (UIKit) Product Version:iOS 10.3 [14E5265a]
Classification:UI/Usability Reproducible:
 
Area:
UIKit

Summary:
I'm trying to strikethrough a UILabel using a NSAttributedString; however, it seems to fail if the UILabel spans multiple lines. Please see the attached project and screenshot.

Steps to Reproduce:
1. Run attached project.

Expected Results:
Both labels would be stricken through.

Actual Results:
Only the shorter, top label is stricken through.

Version:
iOS 10.3 [14E5265a]

Notes:


Configuration:
iPhone 5c 8GB AT&T, iOS Simulator

Comments

Workaround

It appears you can workaround this by setting a baseline offset of 0. I am working in Xamarin Studio, and the following resolved the issue for me:

var attributedString = new NSMutableAttributedString(text); attributedString.AddAttribute(UIStringAttributeKey.BaselineOffset, NSNumber.FromInt32(0), new NSRange(0, message.Length)); attributedString.AddAttribute(UIStringAttributeKey.StrikethroughStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), new NSRange(0, message.Length));

Hopefully this works when translated to Swift too. It looks like this bug is related to: https://openradar.appspot.com/30739102 http://stackoverflow.com/questions/43074652/ios-10-3-nsstrikethroughstyleattributename-is-not-rendered-if-applied-to-a-sub

By michael.bradley.softwire at April 21, 2017, 9:21 a.m. (reply...)

Confirmed to still be present in iOS 10.3.1

Issue is still present in iOS 10.3.1

This also happens with superscript and subscript attributes.

By koenvanderdrift at April 2, 2017, 4:52 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!