iCh*_*rag -1 cocoa-touch objective-c uibutton ios
我在ios上点击了uibutton,检查了很多文章.但通常,人们使用标签属性作为替代.
但我找到了以下解决方案:
UIButton *btnComLike=[[UIButton alloc] init];
[btnComLike setFrame:CGRectMake(127, 20, 30, 15)];
[btnComLike addTarget:self action:@selector(btnCommentLike_click:) forControlEvents:UIControlEventTouchUpInside];
[btnComLike setTitle:@"Like" forState:UIControlStateNormal];
[btnComLike setTitle:@"my any string value" forState:UIControlStateReserved];
Run Code Online (Sandbox Code Playgroud)
和处理方:
-(void)btnCommentLike_click:(id)sender
{
NSLog(@"%@",[sender titleForState:UIControlStateReserved]);
}
Run Code Online (Sandbox Code Playgroud)
这是一个可行的解决方案吗?我认为一方面就是利用这种状态UIControlStateReserved.
或者使用这种技术有任何缺点吗?
如果有,请告诉我有什么问题?