1

サイズをまったく変更せずに、通常の大きなサイズのアイコンで試してみましたが、UIBarButtonItemStyleBorderedは機能します。

UIBarButtonItem *compassButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"compass.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(compassButtonPressed:)];
compassButtonItem.enabled = YES;
self.navigationItem.rightBarButtonItem = compassButtonItem;

UIBarButtonItem initWithImage

次に、UIButtonとCGRectMakeを使用して、画像のサイズを20x20に変更しようとすると、境界線が機能しません。

UIButton *compassButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UIImage *compassImage = [UIImage imageNamed:@"compass.png"];
[compassButton addTarget:self action:@selector(compassButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[compassButton setImage:compassImage forState:UIControlStateNormal];
[compassButton setImage:compassImage forState:UIControlStateSelected];
UIBarButtonItem *compassButtonItem = [[UIBarButtonItem alloc] initWithCustomView:compassButton];
compassButtonItem.style = UIBarButtonItemStyleBordered;
compassButtonItem.enabled = YES;
self.navigationItem.rightBarButtonItem = compassButtonItem;

UIButton setImage

UIImageのサイズを変更してUIBarButtonItemStyleBorderedを使用する方法についてのアイデアはありますか?

4

1 に答える 1

4

どうですか:

UIImage *image = [UIImage imageNamed:@"compass.png"];
CGSize newSize = CGSizeMake(20.0f, 20.0f); 
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIBarButtonItem *compassButtonItem = [[UIBarButtonItem alloc] initWithImage:thumbnail style:UIBarButtonItemStyleBordered target:self action:@selector(refreshSection)];  
self.navigationItem.rightBarButtonItem = compassButtonItem;  
于 2012-10-22T20:19:09.880 に答える