0
我創建像這樣一個按鈕:如何重複使用相同的UIButton多個視圖
UIButton *toTop = [UIButton buttonWithType:UIButtonTypeCustom];
toTop.frame = CGRectMake(12, 12, 37, 38);
toTop.tintColor = [UIColor clearColor];
[toTop setBackgroundImage:[UIImage imageNamed:@"toTop.png"] forState:UIControlStateNormal];
[toTop addTarget:self action:@selector(scrollToTop:) forControlEvents:UIControlEventTouchUpInside];
我有,我想再次反覆使用此相同的按鈕不同的UIViews,但我可以不行。我試過在多個視圖中添加相同的UIButton
,但它總是出現在我添加它的最後一個地方。我也試過:
UIButton *toTop2 = [[UIButton alloc] init];
toTop2 = toTop;
哪個不行。有沒有一種有效的方法來做到這一點,而不是一次又一次地爲同一個按鈕設置所有相同的屬性?謝謝。