IOS_UIButton去掉系统的按下高亮置灰效果

第一种方法:

setAdjustsImageWhenHighlighted   // default is YES. if YES, image is drawn darker when highlighted(pressed)

[cpp]  view plain copy print ?
  1. UIButton *priceBtn = [UIButton buttonWithType:UIButtonTypeCustom];  
  2.  [priceBtn setTag:PRICE_BTN_TAG];  
  3.  [priceBtn setFrame:CGRectMake(DISTANCE_OF_SCREEN_BORDER, 3, 63, 31.5)];  
  4.  [priceBtn setBackgroundColor:[UIColor clearColor]];  
  5.  [priceBtn setImage:[UIImage imageNamed:@"sequence_up_pressed.png"] forState:UIControlStateNormal];  
  6.  [priceBtn addTarget:self action:@selector(priceBtnClicked:) forControlEvents:UIControlEventTouchUpInside];  
  7.  [priceBtn setAdjustsImageWhenHighlighted:NO];  



相关属性:

@property(nonatomic)         BOOL         reversesTitleShadowWhenHighlighted;  // default is NO. if YES, shadow reverses to shift between engrave and emboss appearance

@property(nonatomic)         BOOL         adjustsImageWhenHighlighted;   // default is YES. if YES, image is drawn darker when highlighted(pressed)

@property(nonatomic)         BOOL         adjustsImageWhenDisabled;      // default is YES. if YES, image is drawn lighter when disabled

@property(nonatomic)         BOOL         showsTouchWhenHighlighted;     // default is NO. if YES, show a simple feedback (currently a glow) while highlighted


第二种方法:

本群的Misery-iOS-武汉提到了一个巧妙的方法  正常&高亮用相同的图片

[cpp]  view plain copy print ?
  1. [priceBtn setImage:[UIImage imageNamed:@"sequence_up_pressed.png"] forState:UIControlStateNormal];  
  2. [priceBtn setImage:[UIImage imageNamed:@"sequence_up_pressed.png"] forState:UIControlStateHighlighted];  

你可能感兴趣的:(IOS_UIButton去掉系统的按下高亮置灰效果)