2017-07-01 10 views
0

ボタンのタイトルとイメージのEdgeInsetsを設定すると、ボタンのタイトルとイメージにBLURが表示されます。 (参考スクリーンショットを参照) なぜタイトルと画像がぼやけますか?イメージのエッジインセットとUIButtonのタイトルを変更するとボタンがぼやけて表示されます

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button addTarget:self 
      action:@selector(buttonPressed:) 
forControlEvents:UIControlEventTouchUpInside]; 

CGRect buttonFrame = CGRectMake(0.0, 0.0, mainFrame.size.width, mainFrame.size.height); 
button.frame = buttonFrame; 
[button setTitle:@"Press me" forState:UIControlStateNormal]; 
[button setTitle:@"Pressed" forState:UIControlStateSelected]; 
[button.titleLabel setFont:[UIFont fontWithName:FNT_ALL_TEXTS size:10]]; 

[button setImage:[UIImage imageNamed:imageNormal] forState:UIControlStateNormal]; 
[button setImage:[UIImage imageNamed:imageSelected] forState:UIControlStateSelected]; 
button.imageView.contentMode = UIViewContentModeScaleAspectFit; 
UIImage * refimage = [UIImage imageNamed:imageNormal]; 
[button setTitleEdgeInsets:UIEdgeInsetsMake(buttonFrame.size.height*0.5, -refimage.size.width*1.0, 0.0f, 0.0f)]; 
[button setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, buttonFrame.size.height*0.35, 0.0)]; 
[self addSubview:button]; 

You can see in this image that UIButton image and title are blur

答えて

0

親愛なるだけで、それはボタンのコンテンツの垂直方向と水平方向の配置はしかし、uは、ボタンに画像やテキストを使用していることを確認してください: はここに私のコードです。

UIButton *btn; 
btn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill; 
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill; 

のいずれかに動作しません//水平方向の配置

UIControlContentHorizontalAlignmentLeft 
UIControlContentHorizontalAlignmentRight 
UIControlContentHorizontalAlignmentFill 
UIControlContentHorizontalAlignmentCenter 

// Vertical Alignment 

UIControlContentVerticalAlignmentTop 
UIControlContentVerticalAlignmentFill 
UIControlContentVerticalAlignmentBottom 
UIControlContentVerticalAlignmentCenter 
+0

:( –

関連する問題