objective c - IOS UIButton with AttributedTitle ios -


i have attributed title button in view controller, want button change it's title when clicked example : "add favorite" (clicked change to) "remove favorite".

- (ibaction)addtofav:(id)sender {   nsmutableattributedstring *string,*string2;   string = [[nsmutableattributedstring alloc] initwithstring:@"add favorite"];   string2 = [[nsmutableattributedstring alloc] initwithstring:@"remove favorite"];   if([_btnfav.currentattributedtitle isequaltoattributedstring:string]){     nsattributedstring *attributedtitle = [_btnfav attributedtitleforstate:uicontrolstatenormal];     nsmutableattributedstring *mas = [[nsmutableattributedstring alloc] initwithattributedstring:attributedtitle];     [mas.mutablestring setstring:@"add favorite"];   } else {     nsattributedstring *attributedtitle = [_btnfav attributedtitleforstate:uicontrolstatenormal];     nsmutableattributedstring *mas = [[nsmutableattributedstring alloc] initwithattributedstring:attributedtitle];     [mas.mutablestring setstring:@"remove favorite"];   } } 

- (ibaction)addtofav:(id)sender{   nsstring *string = @"add favorite";   nsstring *string2 = @"remove favorite";   nsstring *newtitle = nil;    nsattributedstring *attributedtitle = [_btnfav attributedtitleforstate:uicontrolstatenormal];   //check title   if([[attributedtitle string] isequaltostring:string]) {     newtitle = string2;   }   else {     newtitle = string;   }   //set title button   nsmutableattributedstring *mas = [[nsmutableattributedstring alloc] initwithstring:newtitle];   [_btnfav setattributedtitle:mas forstate:uicontrolstatenormal]; } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -