buttonWithType
このメソッドを使用して、特定のタイプのUIButtonを取得できることはわかっています。
UIButton * button = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];
今日、私はUIButtonのalloc/initメソッドを何気なく使用してUIButtonを作成します。
UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(20, 300, 100, 50)];
その後、ボタンのタイプを変更する方法がないことがわかりました。UIButtonのbuttonTypeプロパティは読み取り専用であるためです。
UIKit.frameworkでは、UIButton.h:
@property(nonatomic,readonly) UIButtonType buttonType;
私の質問は、alloc / initを使用してUIButtonを作成する場合、UIButtonのタイプを変更できますか?そうでない場合は、 UIButtonのようなinitメソッドがないため、このメソッドを使用して自動リリースUIButtonを取得することしかできません。少し奇妙に聞こえますが、initWithTypeメソッドを提供してみませんか?-initWithType
+buttonWithType