常用控件的初始化

来源:互联网 发布:小白素材vip源码 编辑:程序博客网 时间:2024/04/30 12:10

   //UIView视图

    UIView *gView = [UIViewnew];

    UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(10,10, 10,10)];

    

    //UILabel标签

    UILabel *label0 = [UILabelnew];

    UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(10,40, 50,30)];

    

    //UIWindow窗口_AppDelegate.m

    UIWindow *window = [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

    window.rootViewController = [ViewControllernew];

    [window makeKeyAndVisible];

    

    //UIImageView图片视图

    UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(20,20, 80,80)];

    //(20,20)->视图中心

    imageView.center =self.view.center;

    //位置大小改变

    imageView.frame =CGRectMake(100,100, 100,200);

    [self.viewaddSubview:imageView];

    UIImage *im = [UIImageimageNamed:@"图片名"];

    imageView.image = im;

    //动画

    imageView.image = [UIImageanimatedImageNamed:@"loading_"duration:0.5];

    //内容模式:保持比例适应大小

    imageView.contentMode =UIViewContentModeScaleAspectFit;

    

    //UIControl:控制器

    UIControl *blueC = [[UIControlalloc]initWithFrame:CGRectMake(20,20, 100,100)];

    

    //按钮UIButton

    UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [self.viewaddSubview:btn];

    //位置在屏幕中心大小20070

    btn.frame =CGRectMake(0,0, 200,70);

    btn.center =self.view.center;

    

    //frame相对父视图的尺寸

    CGFloat screenW = [UIScreenmainScreen].bounds.size.width;

    CGFloat screenH = [UIScreenmainScreen].bounds.size.height;

    UIView *blackView = [[UIViewalloc]initWithFrame:CGRectMake(screenW -100 - 20, screenH -100 - 20,100, 100)];

    

    //masory轮子

    UIView *leftBV = [UIViewnew];

    [self.viewaddSubview:leftBV];

    leftBV.backgroundColor = [UIColorlightGrayColor];

    [leftBV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.bottom.equalTo(-20);

        make.left.equalTo(20);

        make.height.width.equalTo(100);

    }];

    

    //UISegmentedControl分段控制器_事件UIControlEventValueChanged

    UISegmentedControl *segment = [[UISegmentedControlalloc]initWithItems:@[@"张三",@"李四",@"王五",@"赵六"]];

    [self.viewaddSubview:segment];

    segment.frame =CGRectMake(20,160, 300,40);

    segment.selectedSegmentIndex =2;



    

    //UISwitch开关_事件UIControlEventValueChanged

    //自定义位置

    UISwitch *sw0 = [[UISwitchalloc]initWithFrame:CGRectMake(50,200, 80,30)];

    UISwitch *sw = [UISwitchnew];

    sw.center =self.view.center;//屏幕中心

    [self.viewaddSubview:sw];

    //默认是开

    sw.on =YES;

    //边框颜色

    sw.tintColor = [UIColororangeColor];

    //开的底色

    sw.onTintColor = [UIColororangeColor];

    //圆球颜色

    sw.thumbTintColor = [UIColorredColor];

    

    //UIActivityIndicatorView活动指示器菊花_UISwith控制isAnimating

    UIActivityIndicatorView *aiv = [[UIActivityIndicatorViewalloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    //可设置位置,大小由Style控制

    aiv.center =self.view.center;//中心

    CGRect rect = aiv.frame;

    rect.origin.x =200;

    rect.origin.y =80;

    aiv.frame = rect;

    

    //UISlider滑动条_事件UIControlEventValueChanged

    //高度默认31,自定义设置无效

    UISlider *slider0 = [UISlidernew];

    CGRect rect0 = slider0.frame;

    rect0.size.width =self.view.frame.size.width - 100;

    slider0.frame = rect0;

    slider0.center =self.view.center;

    UISlider *slider1 = [[UISlideralloc]initWithFrame:CGRectMake(10,50, 100,/*0都为31*/5)];

    

    //UIProgressView进度条高度无效_UISlider控制

    UIProgressView *progressView = [[UIProgressViewalloc]initWithProgressViewStyle:UIProgressViewStyleDefault];

    CGRect rect1 = progressView.frame;

    rect1.size.width = [UIScreenmainScreen].bounds.size.width -100;

    progressView.frame = rect1;

    progressView.center =self.view.center;

    

    //UIStepper步进器_UIControlEventValueChanged

    UIStepper *stepper = [[UIStepperalloc]initWithFrame:CGRectMake(80,150, 80,30)];

    

    //UIPageControl页面控制器

    //只有位置无大小

    UIPageControl *pc = [UIPageControlnew];

    pc.center =self.view.center;

    

    //UITextField文本输入框

    UITextField *tf = [[UITextFieldalloc]initWithFrame:CGRectMake(0,0, [UIScreenmainScreen].bounds.size.width -100, 40)];

    tf.center =self.view.center;

    

    //UIScrollView 滚动视图

    UIScrollView *scrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(20,20, 200,200)];

    scrollView.backgroundColor = [UIColorgreenColor];

    [self.viewaddSubview:scrollView];

    imageView.image = [UIImageimageNamed:@"aad_fjk"];

    [scrollView addSubview:imageView];

    //内容大小

    scrollView.contentSize =CGSizeMake(500,500);

    

    //UITableView表格视图

    UITableView *tableView =[[UITableViewalloc]initWithFrame:CGRectZerostyle:UITableViewStylePlain];//无分组

    [self.viewaddSubview:tableView];

    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.edges.equalTo(0);

    }];

0 0
原创粉丝点击