私は次のようなボタンを作成しました:
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];
この同じボタンを何度も繰り返し使用したいさまざまなUIViewがありますが、それはできません。UIButton
同じものを複数のビューに追加しようとしましたが、最後に追加した場所に常に表示されます。私も試しました:
UIButton *toTop2 = [[UIButton alloc] init];
toTop2 = toTop;
これは機能しません。この同じボタンに同じプロパティを何度も設定せずにこれを行う効率的な方法はありますか?ありがとう。