2010-05-11 64 views
3

我尝试定制中的UITabBar一样iPhone提供自定义UITabBarItem不圆边

我伸出uitabbar项目,现在在它的自定义图像,但我不能摆脱圆滑的边。

代码:

@interface CustomTabBarItem : UITabBarItem 
{ 
    UIImage *customHighlightedImage; 
} 

@property (nonatomic, retain) UIImage *customHighlightedImage; 

@end 

@implementation CustomTabBarItem 

@synthesize customHighlightedImage; 

- (void) dealloc 
{ 
    [customHighlightedImage release]; customHighlightedImage=nil; 
    [super dealloc]; 
} 

-(UIImage *) selectedImage 
{ 
    return self.customHighlightedImage; 
} 

@end 

也许somoen知道如何提前 摆脱了圆角的矩形

图像周围的

感谢亚历克斯

回答

3

感谢与尚未得到批准的自定义标签栏项目

不是苹果解决了这个问题。

进入tabController1.m

- (id) init 
{ 
    if(self = [super init]) 
    { 
     CustomTabBarItem *tabItem = [[CustomTabBarItem alloc] 
            initWithTitle:@"" image:nil tag:0]; 

     tabItem.customHighlightedImage=[UIImage imageNamed:TABBAR_TAB_4_ACTIVE]; 
     tabItem.customStdImage=[UIImage imageNamed:TABBAR_TAB_4_DEFAULT];  

     self.tabBarItem=tabItem; 
     [tabItem release]; 
     tabItem=nil;  
    } 
    return self; 
} 

对自定义tabbaritem:

@interface CustomTabBarItem : UITabBarItem 
{ 
    UIImage *customHighlightedImage; 
    UIImage *customStdImage; 
} 

@property (nonatomic, retain) UIImage *customHighlightedImage; 
@property (nonatomic, retain) UIImage *customStdImage; 

@end 

#import "CustomTabBarItem.h" 


@implementation CustomTabBarItem 

@synthesize customHighlightedImage; 
@synthesize customStdImage; 

- (void) dealloc 
{ 
    [customHighlightedImage release]; customHighlightedImage=nil; 
    [customStdImage release]; customStdImage=nil; 
    [super dealloc]; 
} 

-(UIImage *) selectedImage 
{ 
    return self.customHighlightedImage; 
} 

-(UIImage *) unselectedImage 
{ 
    return self.customStdImage; 
} 

@end 
+0

这是由苹果批准? – CVertex 2010-10-15 06:08:41

+0

是的,它被批准了。搜索“cinemaxx” – 2010-10-15 09:52:28

+0

亚历克斯,你是如何获得红/紫色背景以占用按钮的整个空间的? – Travis 2010-10-28 04:32:09

1

的视图设置cornerRadius已经圆角,以0:

view.layer.cornerRadius = 0; 

此外,你可能需要添加的#include得到的CALayer声明:

#import <QuartzCore/QuartzCore.h> 
+1

谢谢。似乎工作 – 2010-05-11 17:23:21

4

这是肮脏的 - 但作品并得到批准:

  • 调整大小的TabBar
  • 中tabviewcontroller1 init方法

    - (id) init 
    { 
        if(self = [super init]) 
        {  
         CustomTabBarItem *tabItem = [[CustomTabBarItem alloc] 
                initWithTitle:@"" image:nil tag:0]; 
    
         tabItem.customHighlightedImage=[UIImage imageNamed:TABBAR_TAB_1_ACTIVE]; 
         tabItem.customStdImage=[UIImage imageNamed:TABBAR_TAB_1_DEFAULT];  
    
         self.tabBarItem=tabItem; 
         [tabItem release]; 
         tabItem=nil; 
        } 
    
    return self; 
    } 
    

    ,它看起来像

    @interface CustomTabBarItem : UITabBarItem 
        { 
         UIImage *customHighlightedImage; 
         UIImage *customStdImage; 
        } 
    
        @property (nonatomic, retain) UIImage *customHighlightedImage; 
        @property (nonatomic, retain) UIImage *customStdImage; 
    
        @end 
    
    #import "CustomTabBarItem.h" 
    
    
    @implementation CustomTabBarItem 
    
    @synthesize customHighlightedImage; 
    @synthesize customStdImage; 
    
    - (void) dealloc 
    { 
        [customHighlightedImage release]; customHighlightedImage=nil; 
        [customStdImage release]; customStdImage=nil; 
        [super dealloc]; 
    } 
    
    -(UIImage *) selectedImage 
    { 
        return self.customHighlightedImage; 
    } 
    
    -(UIImage *) unselectedImage 
    { 
        return self.customStdImage; 
    } 
    
    @end 
    
    自定义标签栏使用自己的图像在自己的大小

在该选项卡控制器设置

tabController = [[UITabBarController alloc] init]; 
tabController.view.frame = CGRectMake(0, 72, 320, 480 - (82)); 
tabController.delegate = self; 
UIImageView *bgImageView; 
bgImageView = [ [ UIImageView alloc ] initWithImage: [UIImage imageNamed:TABBAR_BACKGROUND]]; 
bgImageView.frame = CGRectMake(0, -11, 320, 60); 

[[tabController tabBar] addSubview:bgImageView]; 
[[tabController tabBar] sendSubviewToBack:bgImageView]; 
tabController.tabBar.frame = CGRectMake(0, 460 - (59 + 52 - 11), 320, 49); 
[bgImageView release]; 

[window addSubview:tabController.view]; 

重要:

我是相当新的iPhone开发和漂亮,漂亮,舒尔,你可以做这样少哈克。此外,我获得了批准,这并不意味着你也会自动运行。

1

我在上面执行的查询。

按照苹果,我们不应该使用私有/未记录的API,

在上面的代码,这两种方法

-(UIImage *) selectedImage { 
    return self.customHighlightedImage; } 

-(UIImage *) unselectedImage { 
    return self.customStdImage; } 

这些方法不是在自定义子类CustomTabBarItem定义。

这些方法的未记录/隐藏方法在UITabBarItem类和在CustomTabBarItem类中重写。

覆盖无证方法可以吗?

我仍然很惊讶这是如何得到苹果公司批准的。 我需要一些澄清在这里。

0

Apple通过此验证码验证过的其他应用程序?非常有兴趣知道我们是否有权使用selectedImage和unselectedImage方法?