Iphone 自定义 UITabBarItem 没有圆角边缘

发布于 2024-09-01 07:41:42 字数 587 浏览 3 评论 0原文

我尝试自定义 uitabbar,

我扩展了 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 知道如何去除

图像周围的

圆角矩形,提前致谢 亚历克斯

i try to customize a uitabbar

i extended uitabbar item and now have a customized image in it but i cant get rid of the rounded edges.

code:

@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

maybe somoen knows how to get rid of the rounded rect

around the image

thanks in advance
alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

青瓷清茶倾城歌 2024-09-08 07:41:42

这很脏 - 但有效并获得批准:

  • 调整标签栏大小,
  • 使用自己大小的图像,

标签控制器设置中

    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];

在 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

重要:< /strong>

我对 iphone 开发还很陌生,并且非常确定你可以用这种方式来减少黑客行为。此外,我获得了批准,但这并不意味着您也会自动获得批准。

This is dirty - but works and got approved:

  • resizes tabbar
  • use your own images in own size

in the tab controller setup

    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];

in the tabviewcontroller1 init method

   - (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;
}

and the custom tab bar it looks like

    @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

IMPORTANT:

i'm pretty new to iphone development and pretty pretty shure you can do this way less hacky. furthermore i got approved with this which does NOT mean you autmoatically will, too.

电影里的梦 2024-09-08 07:41:42

感谢使用自定义选项卡栏项目解决了这个

问题尚未获得苹果批准。

进入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;
}

cutom 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

thanks solved it with custom tab bar items

NOT APPLE APPROVED YET.

goes into 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;
}

cutom 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
行雁书 2024-09-08 07:41:42

将具有圆角的视图上的 cornerRadius 设置为 0:

view.layer.cornerRadius = 0;

此外,您可能需要添加 #include 来获取 CALayer 声明:

#import <QuartzCore/QuartzCore.h>

Set the cornerRadius on the view that has rounded corners to 0:

view.layer.cornerRadius = 0;

Also, you will probably need to add a #include to get the CALayer declarations:

#import <QuartzCore/QuartzCore.h>
扎心 2024-09-08 07:41:42

我对上面的实现有一个疑问。

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

在上面的代码中,

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

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

这两个方法没有在自定义子类 CustomTabBarItem 中定义。

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

重写未记录的方法可以吗?

我仍然很惊讶这怎么能得到苹果的批准。
我需要在这里澄清一些。

I have a query in the above implementation.

As per apple we should not use private / un-documented API's,

In the above code, the two methods

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

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

These methods were not defined in the custom subclass CustomTabBarItem.

These methods are un-documented / hidden methods in UITabBarItem class and overridden in the CustomTabBarItem class.

Is it fine to over-ride the undocumented methods?

I am still surprised how this got approved by Apple.
I need some clarifications here.

-黛色若梦 2024-09-08 07:41:42

Apple 使用此代码验证了其他任何应用程序吗?很想知道我们是否有权使用 selectedImage 和 unselectedImage 方法?

Any other apps validated by Apple with this code ? Very interested to know if we are authorized to use selectedImage and unselectedImage methods ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文