<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                前面寫了UIWindow、UIViewController,那些都是一些框架,框架需要填充上具體的view才能組成我們的應用,移動應用開發中UI占了很大一部分,最基礎的UI實現是使用系統提供的各種控件,其他的就是自定義實現了,作者目前是入門狀態,只能寫寫基礎控件了。 iOS中提供了UIButton、UILable、UITextField、UIImageView等基礎UI控件,繼承于UIView。這里先拿UIButton練練手,為什么拿UIButton呢,因為UIbutton繼承自UIControl,UIControl派生自UIView類,每個控件都有很多視圖的特性,包括附著于其他視圖的能力,所有控件都擁有一套共同的屬性和方法,包含顯示內容,點擊事件等等,UIControl的子類都有事件處理能力。 圖、UIControl ![](https://box.kancloud.cn/2016-01-14_569725c292b88.jpg) **UIButton的定義:** UIButton可使用?initWithFrame、buttonWithType兩種方式創建: 1)initWithFrame ~~~ UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(60, 60, 200, 60)]; btn.backgroundColor=[UIColor greenColor]; [btn setTitle:@"btn1" forState:UIControlStateNormal]; [self.view addSubview:btn]; ~~~ 2)buttonWithType ~~~ UIButton *btn2=[UIButton buttonWithType:UIButtonTypeRoundedRect]; CGRect rect=CGRectMake(60, 160, 200, 60); btn2.frame=rect; btn2.tag=1001; btn2.backgroundColor=[UIColor colorWithRed:30/255.0 green:200/255.0 blue:125/255.0 alpha:1.0]; [btn2 setTitle:@"btn2" forState:UIControlStateNormal]; [btn2 addTarget:self action:@selector(btn2Pressed) forControlEvents:UIControlEventTouchDown]; [self.view addSubview:btn2]; ~~~ btn2Pressed方法: ~~~ -(void)btn2Pressed{ NSLog(@"button pressed"); } ~~~ UIButtonType: ~~~ typedef enum { UIButtonTypeCustom = 0, // no button type 自定義,無風格 UIButtonTypeRoundedRect, // rounded rect, flat white button, like in address card 白色圓角矩形,類似偏好設置表格單元或者地址簿卡片 UIButtonTypeDetailDisclosure,//藍色的披露按鈕,可放在任何文字旁 UIButtonTypeInfoLight,//微件(widget)使用的小圓圈信息按鈕,可以放在任何文字旁 UIButtonTypeInfoDark,//白色背景下使用的深色圓圈信息按鈕 UIButtonTypeContactAdd,//藍色加號(+)按鈕,可以放在任何文字旁 } UIButtonType; } ~~~ **UIButton常用屬性:** //設置對應狀態的標題內容default is nil. title is assumed to be single line -(void)setTitle:(NSString *)title forState:(UIControlState)state; ? //設置對應狀態的標題顏色?? ? ? ? ?? -(void)setTitleColor:(UIColor *)color forState:(UIControlState)state; ?? //設置對應狀態的標題陰影顏色? ? ? ? ? ?? -(void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state; ? ? ? ? ? //設置對應狀態的按鈕的圖片 -(void)setImage:(UIImage *)image forState:(UIControlState)state; ? ? ? ? //設置對應狀態的按鈕背景圖片 -(void)setBackgroundImage:(UIImage*)image forState:(UIControlState)state;? ?? UIButton的UIControlState? ?:?? ?? ~~~ typedef enum { UIButtonTypeCustom = 0, // no button type 自定義,無風格 UIButtonTypeRoundedRect, // rounded rect, flat white button, like in address card 白色圓角矩形,類似偏好設置表格單元或者地址簿卡片 UIButtonTypeDetailDisclosure,//藍色的披露按鈕,可放在任何文字旁 UIButtonTypeInfoLight,//微件(widget)使用的小圓圈信息按鈕,可以放在任何文字旁 UIButtonTypeInfoDark,//白色背景下使用的深色圓圈信息按鈕 UIButtonTypeContactAdd,//藍色加號(+)按鈕,可以放在任何文字旁 } UIButtonType; ~~~ 更多屬性可參考官方文檔。 **UIButton添加事件:** UIButton使用如下方法添加事件。 ~~~ [btn addTarget:<#(id)#> action:<#(SEL)#> forControlEvents:<#(UIControlEvents)#>] ~~~ 這些事件都是基于觸摸、基于值、基于編輯。可相應如下事件。 ~~~ typedef NS_OPTIONS(NSUInteger, UIControlEvents) { UIControlEventTouchDown = 1 << 0, // on all touch downs UIControlEventTouchDownRepeat = 1 << 1, // on multiple touchdowns (tap count > 1) UIControlEventTouchDragInside = 1 << 2, UIControlEventTouchDragOutside = 1 << 3, UIControlEventTouchDragEnter = 1 << 4, UIControlEventTouchDragExit = 1 << 5, UIControlEventTouchUpInside = 1 << 6, UIControlEventTouchUpOutside = 1 << 7, UIControlEventTouchCancel = 1 << 8, UIControlEventValueChanged = 1 << 12, // sliders, etc. UIControlEventEditingDidBegin = 1 << 16, // UITextField UIControlEventEditingChanged = 1 << 17, UIControlEventEditingDidEnd = 1 << 18, UIControlEventEditingDidEndOnExit = 1 << 19, // 'return key' ending editing UIControlEventAllTouchEvents = 0x00000FFF, // for touch events UIControlEventAllEditingEvents = 0x000F0000, // for UITextField UIControlEventApplicationReserved = 0x0F000000, // range available for application use UIControlEventSystemReserved = 0xF0000000, // range reserved for internal framework use UIControlEventAllEvents = 0xFFFFFFFF }; ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看