zoukankan      html  css  js  c++  java
  • 九宫格的实现(转)

    原文来自http://www.ieliwb.com/iphone-nine-box/

    九宫格效果图:

    核心就这2个方法:

    //Power by ieliwb.com
    (void)viewDidLoad {
        
    [super viewDidLoad];
        
        
    NSArrayimageNames = [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=0i<9i++) {
            
    CGRect frame;
            
    Btn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
            
    [Btn setImage:[UIImage imageNamed:[imageNames objectAtIndexi]] 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;
            
    //其他几个控制器类似
        
    }
     
    }

    九宫格背景修改可以这样实现:

    (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(00self.frame.size.width,self.frame.size.height)];
    }
    @
    end

    —-End—-

  • 相关阅读:
    jQuery的标签选择器$('p')、类选择器$('.myClass')、id选择器$('#myId')
    jQuery Validate验证框架与 jQuery ajaxSubmit的联合使用
    23种设计模式(一) 单例模式
    java 常见的几种运行时异常RuntimeException
    Servlet 生命周期、工作原理
    throw与throws的区别
    Apache Shiro java安全框架
    web.xml 中<context-param>与<init-param>的区别与作用
    web.xml 中CharacterEncodingFilter类的学习
    web.xml中的contextConfigLocation在spring中的作用
  • 原文地址:https://www.cnblogs.com/cherri/p/1808790.html
Copyright © 2011-2022 走看看