适用于IOS6.0    

    UIImage *image2 = [UIImage imageNamed:@"header_left_back_normal"];

    CGFloat top = 0; // 顶端盖高度

    CGFloat bottom = 0 ; // 底端盖高度

    CGFloat left = 15; // 左端盖宽度

    CGFloat right = 15; // 右端盖宽度

    UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);

    image2 = [image2 resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeTile];

//    UIImageResizingModeStretch:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片

//    UIImageResizingModeTile:平铺模式,通过重复显示UIEdgeInsets指定的矩形区域来填充图片   

    

    UIButton *backBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];

    backBtn2.frame = CGRectMake(0, 100, screenWidth, 29);

    [backBtn2 setBackgroundImage:image2 forState:UIControlStateNormal];

    [backBtn2 setBackgroundImage:image2 forState:UIControlStateSelected];

    [backBtn2 addTarget:self action: @selector(customDefaultBackButtonClick) forControlEvents: UIControlEventTouchUpInside];

    [backBtn2 setTitle:@"讨论组" forState:UIControlStateNormal];

    [backBtn2.titleLabel setFont:[UIFont fontWithName:@"Arial" size:13]];

    

    [self.view addSubview:backBtn2];

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐