钟表,可以回到起点,却已不是错天

2014.12.8 自定义button

   由于现在出现iPhone6以及iPhone6 plus大屏幕,所以我们进行布局时得考虑自适应,这是我昨天刚刚学习到得。必须得记录一下,希望对你们有帮助,如果有些地方用词不标准得还请提议下,谢谢了,

这是新建得viewcontroller 进行全局定义

 接下来就是定义导航栏

然后现在定义一个方法,在方法下面添加以下代码

 for (int i=0; i<12; i++) {

        label = [[UILabel alloc] init];

        bt = [UIButton buttonWithType:UIButtonTypeCustom];

    

        if (i<4) {

           

            bt.frame=CGRectMake((self.view.bounds.size.width-4*BW)/5+((self.view.bounds.size.width-4*BW)/5+60)*i,70, BW, BH);

            label.frame=CGRectMake((self.view.bounds.size.width-4*BW)/5+((self.view.bounds.size.width-4*BW)/5+60)*i, 70+35, BW, BH);

            label.text=@"label";

//label内容居中

            label.textAlignment=NSTextAlignmentCenter;

            label.adjustsFontSizeToFitWidth=YES;

            label.numberOfLines=1;

            bt.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[NSString stringWithFormat:@"image%i.jpg",i]]];

            bt.layer.cornerRadius=2.0;

       //边框的大小

            bt.layer.borderWidth=2.0;

 //边框得颜色

            bt.layer.borderColor=[[UIColor purpleColor] CGColor];

        }else if (i<8){

            bt.frame=CGRectMake((self.view.bounds.size.width-4*BW)/5+((self.view.bounds.size.width-4*BW)/5+60)*(i%4),BH+70+height, BW, BH);

            label.frame=CGRectMake((self.view.bounds.size.width-4*BW)/5+((self.view.bounds.size.width-4*BW)/5+60)*(i%4), BH+70+height+35, BW, BH);

            label.text=@"label";

            label.textAlignment=NSTextAlignmentCenter;

            label.adjustsFontSizeToFitWidth=YES;

            label.numberOfLines=1;

            bt.layer.cornerRadius=2.0;

        }else if (i<12){

           

            bt.frame=CGRectMake((self.view.bounds.size.width-4*BW)/5+((self.view.bounds.size.width-4*BW)/5+60)*(i%4),(i/4)*(BH+height)+70, BW, BH);

            label.frame=CGRectMake((self.view.bounds.size.width-4*BW)/5+((self.view.bounds.size.width-4*BW)/5+60)*(i%4), (i/4)*(BH+height)+70+35, BW, BH);

            label.text=@"label";

            label.textAlignment=NSTextAlignmentCenter;

            label.adjustsFontSizeToFitWidth=YES;

            label.numberOfLines=1;

            bt.layer.cornerRadius=2.0;

        }

//        bt.backgroundColor=[UIColor redColor];

        bt.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[NSString stringWithFormat:@"image%i.jpg",i]]];

        [self.view addSubview:bt];

        [self.view addSubview:label];

    }

  现在我们运行看一下结果

 

posted @ 2014-12-09 09:42  独一无二  阅读(141)  评论(0编辑  收藏  举报
世界上没有绝望得处境,只有对处境绝望得人