C++方法可以做到参数可以按值引用,Objective-C不可以吗?
看代码:
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame=CGRectMake(50,50,300,50);
[buttonsetTitle:@"我是一个按钮" forState:UIControlStateNormal];
[buttonaddTarget:self action:@selector(Method:) forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
// Do any additional setup after loading the view.
}
- (void)Method:(UIButton*)sender
{
sender.backgroundColor = [UIColor colorWithRed:arc4random() % 255 / 255.0 green:arc4random() % 255 / 255.0 blue:arc4random() % 255 / 255.0 alpha:1.f];
}
看效果
未命名.gif
网友评论