我在发布iOS 10.3之前使用过这行代码,并且工作正常。
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",strMRP,strOffer]];
[attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:NSMakeRange(0, strMRP.length)];
[attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:15] range:NSMakeRange(strMRP.length, strOffer.length+1)];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
value:[NSNumber numberWithInteger: NSUnderlineStyleDouble]
range:NSMakeRange(0,strMRP.length)];
但是现在它停止了工作,有没有其他方法可以进行罢工?
答案 0 :(得分:8)
这是iOS 10.3中的错误, NSStrikethroughStyleAttributeName
(任何NSUnderlineStyle
个案例)在iOS SDK 10.3上不再有效。< / p>
如果有人发现与此相关的更新答案,请通知此处,我会更新我的答案。
产品版本:10.3
创建时间:2017年3月14日
发起时间:2017年3月14日
打开雷达链接:http://www.openradar.appspot.com/31034683
雷达状态目前为打开状态
您也可以看到替代样本here可能有用。
答案 1 :(得分:5)
我在developer forum找到了一个解决方法,这对我有用。将NSBaselineOffsetAttributeName
添加到字符串属性修复了此问题:)
答案 2 :(得分:3)
可以正常使用
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",strMRP,strOffer]];
[attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:NSMakeRange(0, strMRP.length)];
[attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:15] range:NSMakeRange(strMRP.length, strOffer.length+1)];
[attributeString addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithInteger: NSUnderlineStyleNone]
range:NSMakeRange(0,strMRP.length)];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
value:[NSNumber numberWithInteger: NSUnderlineStyleDouble]
range:NSMakeRange(0,strMRP.length)];
答案 3 :(得分:1)
iOS 10.3以后你需要添加NSBaselineOffsetAttributeName。
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",strMRP,strOffer]];
[attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:NSMakeRange(0, strMRP.length)];
[attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:15] range:NSMakeRange(strMRP.length, strOffer.length+1)];
[attributeString addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithInteger: NSUnderlineStyleNone]
range:NSMakeRange(0,strMRP.length)];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
value:[NSNumber numberWithInteger: NSUnderlineStyleDouble]
range:NSMakeRange(0,strMRP.length)];
添加NSBaselineOffsetAttributeName后,它适用于单行,双行等。
答案 4 :(得分:0)
如上所述,这是一个iOS 10.3错误。
我们需要立即解决方法,以防万一有人在寻找提示:
我们的标签具有通过class Employee(object):
def __init__(self, name, idno, position, salary):
self.name=name
self.idno=idno
self.position=position
self.salary = salary
def print_data(self):
print("Name:", self.name, "Idno:", self.idno, "position:", self.position,
"salary:", self.salary)
if __name__=='__main__':
def input_employee_data():
print('Enter data for an employee')
name = raw_input("Name:")
idno = raw_input("Idno:")
position = raw_input("position:")
salary = raw_input("salary:")
print('')
return name, idno, position, salary
employees = list()
n = int(raw_input("Enter the number of employees:"))
for i in range(n):
name, idno, position, salary = input_employee_data()
employee = Employee(name, idno, position, salary)
employees.append(employee)
print('List of employess')
for employee in employees:
employee.print_data()
和NSMutableAttributedString
设置的属性。使用no / an&#34; empty&#34;时没有发生错误。段落样式(没有设置任何属性的实例)。
因此,在这种情况下,省略段落样式并解决当时缺少的段落属性为我们解决了问题。
答案 5 :(得分:0)
只需使用: -
NSMutableAttributedString * costPrice = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@“₹%@”,strDetails]]; [costPrice addAttribute:NSBaselineOffsetAttributeName 值:[NSNumber numberWithInteger:NSUnderlineStyleSingle]范围:NSMakeRange(0,costPrice.length)];
这是临时解决方案。希望它有效
答案 6 :(得分:0)
***你可以将它传递给功能&amp;请享用 !!!
new_data <- birds@data
new_data
# SpecimenID lat lon in_plant
# 1 1 46.06667 7.600000 0
# 2 2 46.60134 9.965973 0
# 3 3 46.02360 7.748607 0
# 4 4 46.60134 9.965973 0
# 5 5 46.91833 13.873611 0
# ...
# 48 48 40.01861 -105.278056 1
# 49 49 40.02977 -105.581228 1
# 50 50 47.05917 13.615556 0
并使用如:
func customString(currentprice:String,oldPrice:String) -> NSMutableAttributedString{
// 1
let NewString = currentprice + " " + oldPrice
let string = NewString as NSString
let attributedString = NSMutableAttributedString(string: string as String)
// 2
let firstAttributes = [NSForegroundColorAttributeName: UIColor(red: 238/255, green: 140/255, blue: 84/255, alpha: 1),NSBaselineOffsetAttributeName:1]
let secondAttributes = [NSForegroundColorAttributeName: UIColor.lightGrayColor(), NSStrikethroughStyleAttributeName: 1]
// 3
attributedString.addAttributes(firstAttributes, range: string.rangeOfString(currentprice))
attributedString.addAttributes(secondAttributes, range: string.rangeOfString(oldPrice))
return attributedString
}