导航栏先关设计

来源:互联网 发布:软件测试怎么自学 编辑:程序博客网 时间:2024/06/06 03:55


//设计导航条背景图片

if ([[UIDevicecurrentDevice].systemVersionfloatValue] >= 5.0 ) {

        

        [self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"Topbar_Img.png"]forBarMetrics:UIBarMetricsDefault];

    }else{

        

        self.navigationController.navigationBar.layer.contents = (id)[UIImageimageNamed: @"Topbar_Img.png"].CGImage;

        

        

    }


//在导航上添加按钮

UIView *tempView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 80, 44)];

    

    UIButton *right =[[UIButtonbuttonWithType:UIButtonTypeCustom]retain];

    [right setImage:[UIImageimageNamed:@"filter.png"  ]forState:UIControlStateNormal];

    right.frame =CGRectMake(50, 6,31, 31);

    right.exclusiveTouch =YES;

    [right addTarget:selfaction:@selector(riddling)forControlEvents:UIControlEventTouchUpInside];

    

    UIButton *photo =[[UIButtonbuttonWithType:UIButtonTypeCustom]retain];

    [photo setImage:[UIImageimageNamed:@"puzzle.png"  ]forState:UIControlStateNormal];

    photo.frame =CGRectMake(10, 6+2,31, 31);

    photo.exclusiveTouch =YES;

    [photo addTarget:selfaction:@selector(goPuzzle)forControlEvents:UIControlEventTouchUpInside];

    

    [tempView addSubview:right];

    [tempView addSubview:photo];

    [right release];

    [photo release]; 

    

    UIBarButtonItem *ubbi =[[UIBarButtonItemalloc] initWithCustomView:tempView];

  self.navigationItem.rightBarButtonItem =ubbi;

    [ubbi release];



//设计导航图片的,重写该方法,实现导航图片的方法2

@implementation UINavigationBar (CustomImage)



- (void)drawRect:(CGRect)rect {

//设计按钮的颜色

    [selfsetTintColor:[UIColorcolorWithRed:0.83green:0.89blue:0.62alpha:0.7]];

//设计导航栏的图片的

    UIImage *image = [UIImageimageNamed: @"Topbar_Img.png"];

//将图片放入导航栏

    [image drawInRect:CGRectMake(0,0, self.frame.size.width,self.frame.size.height)];

}


@end



//在导航视图中添加按钮

UIBarButtonItem *leftBtn = [[UIBarButtonItemalloc]

initWithTitle:@"next" 

style:UIBarButtonItemStyleBordered

                                target:self

                                action:@selector(pushController)];           //监听要做出的响应

self.navigationItem.leftBarButtonItem = leftBtn;

//设计导航图片的方法1

    //self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed: @"Topbar_Img.png"].CGImage;

//设计导航颜色的

//self.navigationController.navigationBar.tintColor = [UIColor yellowColor];

//[self.navigationController.navigationBar setTintColor:[UIColor colorWithRed:0.83 green:0.89 blue:0.62 alpha:0.7]];




原创粉丝点击