加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

iPhone九宫格的达成

发布时间:2021-11-24 15:48:28 所属栏目:PHP教程 来源:互联网
导读:看到很多同学在问,其实很简单,我这是用图片堆砌实现的九宫格,分享如下: 效果图: 核心就这2个方法: [plain] //Power by ieliwb.com - (void)viewDidLoad { [super viewDidLoad]; NSArray* imageNames = [NSArray arrayWithObjects: @ico_mobile.png, @ico_idca
看到很多同学在问,其实很简单,我这是用图片堆砌实现的九宫格,分享如下:
 
效果图:
 
 
核心就这2个方法:
 
 
[plain]
//Power by ieliwb.com  
- (void)viewDidLoad {  
    [super viewDidLoad];  
      
    NSArray* imageNames = [NSArray arrayWithObjects:  
                                        @"ico_mobile.png",   
                                        @"ico_idcard.png",   
                                        @"ico_postcode.png",  
                                        @"ico_flight.png",   
                                        @"ico_translate.png",  
                                        @"ico_phone.png",   
                                        @"ico_car.png",   
                                        @"ico_health.png",   
                                        @"ico_bjxm.png", nil];  
   
    UIButton *Btn;  
    for (int i=0; i<9; i++) {  
        CGRect frame;  
        Btn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];  
        [Btn setImage:[UIImage imageNamed:[imageNames objectAtIndex: i]]forState:UIControlStateNormal];//设置按钮图片  
          
        Btn.tag = i;  
          
        frame.size.width = 59;//设置按钮坐标及大小  
        frame.size.height = 75;  
        frame.origin.x = (i%3)*(59+32)+40;  
        frame.origin.y = floor(i/3)*(75+24)+40;  
        [Btn setFrame:frame];  
          
        [Btn setBackgroundColor:[UIColor clearColor]];  
        [Btn addTarget:self action:@selector(btnPressed:)forControlEvents:UIControlEventTouchUpInside];  
        [self.view addSubview:Btn];  
        [Btn release];  
          
    }  
          
}  
   
//响应按钮事件  
-(void)btnPressed:(id)sender{  
    UIButton *Btn = (UIButton *)sender;  
        int index = Btn.tag;  
      
    switch (index) {  
        case 0:  
            if(mobileController==nil)  
                mobileController = [[MobileController alloc]init];  
            [self.navigationController pushViewController:mobileControlleranimated:YES];  
            break;  
        //其他几个控制器类似  
    }  
   
}  
九宫格背景修改可以这样实现:
 
[plain]
- (void)loadView {  
    UIImageView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreenmainScreen] applicationFrame]];  
    [contentView setImage:[UIImage imageNamed:@"subview_9_bg.png"]];  
    [contentView setUserInteractionEnabled:YES];  
    self.view = contentView;  
    [contentView release];  
}  
UINavigationBar背景图片可以这样实现:  
  
@implementation UINavigationBar (CustomImage)  
- (void)drawRect:(CGRect)rect {  
    UIImage *image = [UIImage imageNamed: @"top_bg.png"];  
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height)];  
}  
@end  
 

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读