iOS tintColor 小结

本文深入解析了UIKit中的TintColor属性与TintAdjustmentMode属性,阐述了它们如何影响视图及其子控件的颜色表现,尤其是在iOS 7.0及以后的版本中。文章详细解释了TintColor用于设定视图及其子控件的状态颜色,而TintAdjustmentMode则决定了颜色调整模式,当设为Dimmed时,颜色将呈现灰暗效果。同时,文中还提到了当这两个属性发生变化时,系统会自动调用子类的tintColorDidChange方法,以刷新视图的渲染。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
 -tintColor always returns a color. The color returned is the first non-default value in the receiver's superview chain (starting with itself).
 If no non-default value is found, a system-defined color is returned.
 If this view's -tintAdjustmentMode returns Dimmed, then the color that is returned for -tintColor will automatically be dimmed.
 If your view subclass uses tintColor in its rendering, override -tintColorDidChange in order to refresh the rendering if the color changes.
 */
@property(null_resettable, nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(7_0);

/*
 -tintAdjustmentMode always returns either UIViewTintAdjustmentModeNormal or UIViewTintAdjustmentModeDimmed. The value returned is the first non-default value in the receiver's superview chain (starting with itself).
 If no non-default value is found, UIViewTintAdjustmentModeNormal is returned.
 When tintAdjustmentMode has a value of UIViewTintAdjustmentModeDimmed for a view, the color it returns from tintColor will be modified to give a dimmed appearance.
 When the tintAdjustmentMode of a view changes (either the view's value changing or by one of its superview's values changing), -tintColorDidChange will be called to allow the view to refresh its rendering.
 */
@property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode NS_AVAILABLE_IOS(7_0);

/*
 The -tintColorDidChange message is sent to appropriate subviews of a view when its tintColor is changed by client code or to subviews in the view hierarchy of a view whose tintColor is implicitly changed when its superview or tintAdjustmentMode changes.
 */
- (void)tintColorDidChange NS_AVAILABLE_IOS(7_0);

  1. tintColor 属性是一个可以影响子控件和自身状态颜色的一个属性例如UIButton(系统样式默认是蓝色的)

  2. 2. tintColor 和  tintAdjustmentMode 在发生改变的时候系统会递归调用子类的tintColorDidChange方法,一些系统类实现了这个效果例如 : UIButton,UIStepper, UITextfield, UITextView, UIProgressView, UISegmentedControl, 导航栏和TabBar,ToolBar上的文字和系统的默认图片等


 

tintColor效果
tintColor效果
​​​​​​


3 . 当设置 tintAdjustmentMode 这个属性为dimed时候系统会在tintColor的基础上让颜色变成灰色的 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值