码迷,mamicode.com
首页 > 其他好文 > 详细

在button中加入一个view图片

时间:2015-09-17 01:02:23      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatPic];
    
}

- (void)creatPic
{
    for (int i=0; i<3; i++) {
        
        //创建button
        UIButton *btn1=[[UIButton alloc] init];
        
        btn1.frame=CGRectMake(50, 50+i*180, 300, 150);
        
        [self.view addSubview:btn1];
        
        btn1.backgroundColor=[UIColor cyanColor];
        
        //创建UIImageView
        UIImageView *iv1=[[UIImageView alloc] init];
        
        iv1.frame=CGRectMake(20, 20, 180, 110);
        
        [btn1 addSubview:iv1];
        
        iv1.backgroundColor=[UIColor blueColor];
        
        iv1.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]];
        
        iv1.contentMode=UIViewContentModeScaleToFill;
        
        iv1.alpha=0.8;
        
        //创建按钮
        UILabel *label1=[[UILabel alloc] init];
        UILabel *label2=[[UILabel alloc] init];
        
        label1.text=@"名字";
        label2.text=@"详情";
        
        label1.textAlignment=NSTextAlignmentCenter;
        label2.textAlignment=NSTextAlignmentCenter;
        
        label1.textColor=[UIColor blackColor];
        label2.textColor=[UIColor blackColor];
        
        label1.frame=CGRectMake(270, 120+i*180, 60, 25);
        label2.frame=CGRectMake(270, 160+i*180, 60, 25);
        
        label1.backgroundColor=[UIColor grayColor];
        label2.backgroundColor=[UIColor greenColor];
        
        [self.view addSubview:label1];
        [self.view addSubview:label2];
     }
}


        
技术分享

技术分享

技术分享

//这是.jpg图片

这里在一个循环三次的函数中创建了button,imageView等

技术分享

//这是最后的运行结果

在button中加入一个view图片

标签:

原文地址:http://www.cnblogs.com/wanghengheng/p/4814931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!