当前位置:编程学习 > wap >>

ios开发之UIButton 点击两张图标转换

现在想定义一个UIButton, 这个button有两张图片, 一张算是背景图, 另外一张显示图片1.
         我通过setBackgroundImage设置了背景图片, 用setImage 来设置显示图片  但是因为图片 大于了我设置的按钮的大小, 所以显示出来的效果是图片 超出了按钮的框架.....
 
 
         
          
          第一个按钮是两张图片重叠的时候, 后面两个是分别单独加载的时候...
          源代码是这样的:www.zzzyk.com
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn1 setFrame: CGRectMake(10, 10, 50, 50)];
        [btn1 setBackgroundImage:[UIImage imageNamed: @"ui4.png"] forState:UIControlStateNormal];
        [btn1 setImage:[UIImage imageNamed:@"icon0.png"] forState:UIControlStateNormal];
        btn1.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview: btn1];
        
        UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btn2 setFrame: CGRectMake(65, 10, 50, 50)];
        [btn2 setBackgroundImage:[UIImage imageNamed: @"ui4.png"] forState:UIControlStateNormal];
        btn2.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview: btn2];
        
        UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btn3 setFrame: CGRectMake(120, 10, 50, 50)];
        btn2.contentMode = UIViewContentModeCenter;
        [btn3 setBackgroundImage:[UIImage imageNamed:@"icon0.png"] forState:UIControlStateNormal];
        [self addSubview: btn3];
 
补充:移动开发 , IOS ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,