iphone - respond to selector method for unsupported implementations -
in app need display under line text in label used following code display underlined text
nsmutableattributedstring *attributestring = [[nsmutableattributedstring alloc] initwithstring:normalstring]; [attributestring addattribute:nsunderlinestyleattributename value:[nsnumber numberwithint:1] range:(nsrange){0,[attributestring length]}]; wesiteaddresslabel.attributedtext = attributestring;
this method , other implementations works fine in ios 6.1
but when executed in ios 5.1 , below, app gets crashed due reason,
[attributestring addattribute:nsunderlinestyleattributename value:[nsnumber numberwithint:1] range:(nsrange){0,[attributestring length]}];
not supported in previous versions
so want use respondstoselector:
method check if instance responds , implement method unsupported selector.
how use method?
as documentation:
attributedtext styled text displayed label.
@property(nonatomic,copy) nsattributedstring *attributedtext discussion property nil default. assigning new value property replaces value of text property same string data, albeit without formatting information. in addition, assigning new value updates values in font, textcolor, , other style-related properties reflect style information starting @ location 0 in attributed string.
availability available in ios 6.0 , later. declared in uilabel.h
you should check if specific uiview
element able respond attributedtext
. in case:
[wesiteaddresslabel respondstoselector:@selector(attributedtext)];
should enough
Comments
Post a Comment