UIButtonの基本プロパティと定義


  • 第一、UIButtonの定義
  •   UIButton *button=[[UIButton buttonWithType:(UIButtonType);

    定義できるbuttonタイプは以下の6種類あり、
      typedef enum {
      UIButtonTypeCustom = 0,  
      UIButtonTypeRoundedRect,  
      UIButtonTypeDetailDisclosure,  , 
      UIButtonTypeInfoLight,  
      UIButtonTypeInfoDark,  
      UIButtonTypeContactAdd,  
      } UIButtonType;
  • 第2、frame
  • を設定
      button1.frame = CGRectMake(20, 20, 280, 40);
      [button setFrame:CGRectMake(20,20,50,50)];
  • 第三、button背景色
  •   button1.backgroundColor = [UIColor clearColor];
      [button setBackgroundColor:[UIColor blueColor]];
  • 第4、state状態forState:このパラメータの役割は、ボタンの文字または画像がどの状態で現れるかを定義する
  • である.
      enum {
      UIControlStateNormal = 0,  
      UIControlStateHighlighted = 1 << 0,  
      UIControlStateDisabled = 1 << 1,  
      UIControlStateSelected = 1 << 2,  
      UIControlStateApplication = 0x00FF0000,  
      UIControlStateReserved = 0xFF000000  , 
      };
      @property(nonatomic,getter=isEnabled)BOOL enabled; // default is YES. if NO, ignores touch events and subclasses may draw differently
      @property(nonatomic,getter=isSelected)BOOL selected; // default is NO may be used by some subclasses or by application
      @property(nonatomic,getter=isHighlighted)BOOL highlighted;
  • 第5、buttonパディングピクチャと背景ピクチャ
  • を設定する
      [buttonsetImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];
      [buttonsetBackgroundImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];
  • 第6、buttonタイトルとタイトル色
  • を設定する
      [button1 setTitle:@" " forState:UIControlStateNormal];
      [buttonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];
  • 第7、設定ボタンが押下すると発光する
  • .
     button.showsTouchWhenHighlighted=NO;
  • 第8、追加又は削除イベント処理
  •   [button1 addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];
      [btn removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
  • 第9、ボタン内部のピクチャピッチとタイトルピッチ
  • を設定する.
      UIEdgeInsets insets; //  
      insets.top = insets.bottom = insets.right = insets.left = 10;
      bt.contentEdgeInsets = insets;
      bt.titleEdgeInsets = insets; //