Posts

Showing posts with the label UILabel

add small image after text in UILabel

NSTextAttachment * attachment = [[ NSTextAttachment alloc ] init ]; attachment . image = [ UIImage imageNamed :@ "myimage.png" ]; NSAttributedString * attachmentString = [ NSAttributedString attributedStringWithAttachment : attachment ]; NSMutableAttributedString * myString = [[ NSMutableAttributedString alloc ] initWithString :@ "My label text" ]; [ myString appendAttributedString : attachmentString ]; myLabel . attributedText = myString ;

Struck through text in UILabel

In iOS 6.0 and up UILabel supports NSAttributedString NSMutableAttributedString * attributeString = [[ NSMutableAttributedString alloc ] initWithString :@ "Your String here" ]; [ attributeString addAttribute : NSStrikethroughStyleAttributeName value :@ 2 range : NSMakeRange ( 0 , [ attributeString length ])]; Definition : - ( void ) addAttribute :( NSString *) name value :( id ) value range :( NSRange ) aRange Parameters List: 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. value : The attribute value associated with name. aRange : The range of characters to which the specified attribute/value pair applies. Then yourLabel . attributedText = attributeString ;