码迷,mamicode.com
首页 > 其他好文 > 详细

How to duplicate a UIButton in Objective C?

时间:2015-01-30 15:37:44      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

http://stackoverflow.com/questions/1092875/how-to-duplicate-a-uibutton-in-objective-c

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?

标签:

原文地址:http://www.cnblogs.com/xuejinhui/p/4262199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!