ios之拖控制項篇1

來源:互聯網
上載者:User

ios之拖控制項篇1

1.IBAction:

1> 能保證方法可以連線

2> 相當於void

-(IBAction)


2.IBOutlet:

1> 能保證屬性可以連線

@property (weak,nonatomic)IBOutlet



3.常見錯誤

setValue:forUndefinedKey:]: this class is not key value coding

錯誤原因是:連線出問題了


4.Xcode5開始的一些建議

把用於連線的一些方法和屬性聲明在.m檔案的類擴充中

 CGRect tempBounds = self.head.bounds;        // 2.改變臨時屬性    tempBounds.size.width += 20;    tempBounds.size.height += 20;        // 3.用臨時屬性覆蓋原來的屬性    self.head.bounds = tempBounds;


5.frame\center\bounds

1> frame:能修改位置和尺寸

不能用點文法直接修改frame屬性的值

  CGRect btnFrame = self.controlName.frame;  btnFrame.origin.y -= 10;  self.controlName.frame = btnFrame;

2> center:能修改位置

不能用點文法直接修改center屬性的值

CGPoint tempCenter = self.head.center;tempCenter.x += 10;self.head.center = tempCenter;


3> bounds:能修改尺寸(x\y一般都是0)

不能用點文法直接修改bounds屬性的值

 CGRect tempBounds = self.head.bounds; tempBounds.size.width += 20; self.head.bounds = tempBounds;



6.自動產生連線資訊

按住control 拖控制項



7.代碼動態建立控制項

- (void)viewDidLoad{    [super viewDidLoad];        NSLog(@"-----viewDidLoad");    // 添加        // 1.建立按鈕    UIButton *btn = [[UIButton alloc] init];        // 2.添加按鈕    [self.view addSubview:btn];        // 3.設定frame    btn.frame = CGRectMake(100, 100, 100, 100);        // 4.設定背景色    btn.backgroundColor = [UIColor blueColor];    //    UIImage *image = [UIImage imageNamed:@"btn_01"];//    [btn setBackgroundImage:image forState:uicontrolstate];}


8.簡單的過度動畫


   // 0.開始動畫    [UIView beginAnimations:nil context:nil];        // 動畫持續2秒    [UIView setAnimationDuration:2.0];        // 1.取出原來的屬性    CGRect tempBounds = self.head.bounds;        // 2.改變臨時屬性    tempBounds.size.width += 50;    tempBounds.size.height += 50;        // 3.用臨時屬性覆蓋原來的屬性    self.head.bounds = tempBounds;        // 4.提交動畫    [UIView commitAnimations];




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.