我使用以下代码
[yourVIEw.layer setborderWIDth:5.0];[yourVIEw.layer setbordercolor:[[UIcolor colorWithPatternImage:[UIImage imagenamed:@"DotedImage.png"]] CGcolor]];///just add image name and create image with dashed or doted drawing and add here
但它没有完美的工作,我想实现适当的方法,我怎么能实现这一点.使用这些也不合适Link1,Link2,Link3,Link4
我能够使用以下代码解决
NSAttributedString * Title = [[NSAttributedString alloc] initWithString:@"I implement My test in here" attributes:@{NsstrikethroughStyleAttributename:@(NSUnderlinestyleSingle)}]; [ self.vIEwOrderCell.labelitem setAttributedText:Title];解决方法 你可能意味着Strike,iOS 6.0和更高版本,UILabel支持NSAttributedString和NSMutableAttributedString
使用NSAttributedString时
NSAttributedString * Title = [[NSAttributedString alloc] initWithString:@"Your String here" attributes:@{NsstrikethroughStyleAttributename:@(NSUnderlinestyleSingle)}];[label setAttributedText:Title];
定义:
/** * Returns an NSAttributedString object initialized with a given string and attributes. * * @param str : The string for the new attributed string. * @param attrs : The attributes for the new attributed string. For information * about where to find the attribute keys you can include in this dictionary,* see the overvIEw section of this document. * * @return Returns an NSAttributedString object initialized with the characters of aString and the attributes of attributes. The returned object might be different from the original receiver. */- (instancetype)initWithString:(Nsstring *)str attributes:(NSDictionary *)attrs;
使用NSMutableAttributedString时
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Your String here"];[attributeString addAttribute:NsstrikethroughStyleAttributename value:@2 range:NSMakeRange(0,[attributeString length])];
定义:
/** * * @param name : A string specifying the attribute name. Attribute keys can be * supplIEd by another framework or can be custom ones you define. For * information about where to find the system-supplIEd attribute keys,see the * overvIEw section in NSAttributedString Class Reference. * * @param value : The attribute value associated with name. * * @param arange : The range of characters * to which the specifIEd attribute/value pair applIEs. */- (voID)addAttribute:(Nsstring *)name value:(ID)value range:(NSRange)arange;
然后
yourLabel.attributedText = attributeString;总结
以上是内存溢出为你收集整理的如何在ios objective-c中使用NSAttributedString在多行标签中添加背景行全部内容,希望文章能够帮你解决如何在ios objective-c中使用NSAttributedString在多行标签中添加背景行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)