ios4--UIView的常見屬性(尺寸和位置)

來源:互聯網
上載者:User

標籤:方式   pre   class   uiview   log   控制   添加   ace   背景   

////  ViewController.m//  08-UIView的常見屬性(尺寸和位置)////  frame:相對於父控制項左上方定位//  bounds:改變長寬,左上方是相對於自己//  center:#import "ViewController.h"@interface ViewController ()/** label */@property (nonatomic, weak) UILabel *label;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // 建立UILabel對象    UILabel *label = [[UILabel alloc] init];    // 設定frame (位置和尺寸)    label.frame = CGRectMake(100, 100, 100, 60); //父控制項作為原點    // 設定背景顏色    label.backgroundColor = [UIColor yellowColor];        // 添加到控制器的view中    [self.view addSubview:label];  //添加進去了    self.label = label;}- (IBAction)bounds {    // 改變尺寸  iOS9以後, 中心點不變,向四周延伸    self.label.bounds = CGRectMake(30, 30, 200, 120);}- (IBAction)center {   // 改變位置   // self.label.center = CGPointMake(100, 100);        // 顯示在最中間    self.label.center = CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.5);    }- (IBAction)changeFrame {    // 方式1//    self.label.frame = CGRectMake(200, 100, 100, 60);        // 方式2    self.label.frame = (CGRect){{100, 100}, {100, 100}};        // 方式3    // 結構體是值傳遞,不是地址傳遞//    self.label.frame.size.width += 100;    CGRect frame = self.label.frame;//    frame.origin.x -= 100; // 改變x值//    frame.origin.y += 100; // 改變y值//    frame.size.width += 50; // 改變寬度    frame.size.height += 100; // 改變高度    self.label.frame = frame;    }@end

 

ios4--UIView的常見屬性(尺寸和位置)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.