How to duplicate a UIButton in Objective C?
2024-11-22 17:39:02 202人阅读
http://stackoverflow.com/questions/1092875/how-to-duplicate-a-uibutton-in-objective-c
1down vote | To add to Jim‘s answer above using a category @implementation UIButton (NSCopying) - (id)copyWithZone:(NSZone *)zone { NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self]; UIButton *buttonCopy = [NSKeyedUnarchiver unarchiveObjectWithData: archivedData]; return buttonCopy; } @end
if you wanted to copy all of the actions from one button to another, add something like this: for (id target in button.allTargets) { NSArray *actions = [button actionsForTarget:target forControlEvent:UIControlEventTouchUpInside]; for (NSString *action in actions) { [newButton addTarget:target action:NSSelectorFromString(action) forControlEvents:UIControlEventTouchUpInside]; }
|
How to duplicate a UIButton in Objective C?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。