2011-10-31 2 views
3

UIBarButtonItemをカスタマイズしたい、ここに私のコードがあります。ios5でUIBarButtonItemをカスタマイズする方法

ios4.3では動作しますが、ios5では非常に奇妙です。 uibarbuttonitemは見えないところに姿を消していますが、それはまだeffect.Asを持っている上に透明であるをクリックします。

私は助けを必要とし、uibarbuttonitemのdisplay.thanksようにする方法を

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
btn.frame = CGRectMake(0, 0, 50, 30); 
[btn setBackgroundImage:[UIImage imageNamed:@"btnRegister.png"] forState:UIControlStateNormal]; 
[btn setTitle:@"register" forState:UIControlStateNormal]; 
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
[btn addTarget:self action:@selector(registerClick:) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:btn]; 
self.navigationItem.rightBarButtonItem = item1; 

答えて

0

私の問題は、に似ていますこれです。私の場合、ボタンは有効にならないように見えます。そしてあなたがそれを置くときにはまだ効果があります。一つの小さな解決策は白で、ボタンの色合いを変えているが、私はより良い方法を探しています:)

私のコードは次のとおりです。

buttonImage = [UIImage imageNamed:@"top_icon_share.png"]; 
UIButton *buttonShare = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height)]; 
[buttonShare setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
[buttonShare addTarget:self action:@selector(buttonSharePressed) 
     forControlEvents:UIControlEventTouchUpInside]; 
[buttonShare setShowsTouchWhenHighlighted:YES];]; 
    UIBarButtonItem *buttonBarShare = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"top_icon_share.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonSharePressed:)]; 
6

のiOS 5の新カスタマイズ機能についての素晴らしいチュートリアルはここにあります:http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5

ここではそのかなり自明、UIBarButtonItemsのカスタマイズを扱っているサイトからのコードのコピーです:

UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)]; 
UIImage *button24 = [[UIImage imageNamed:@"button_textured_24"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)]; 

[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal 
barMetrics:UIBarMetricsDefault]; 
[[UIBarButtonItem appearance] setBackgroundImage:button24 forState:UIControlStateNormal 
barMetrics:UIBarMetricsLandscapePhone]; 

[[UIBarButtonItem appearance] setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys: 
    [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], 
    UITextAttributeTextColor, 
    [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], 
    UITextAttributeTextShadowColor, 
    [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], 
    UITextAttributeTextShadowOffset, 
    [UIFont fontWithName:@"AmericanTypewriter" size:0.0], 
    UITextAttributeFont, 
    nil] 
forState:UIControlStateNormal]; 
関連する問題