Home Photos Games Read Others Ambrose yongxu 's blog, life and learn

开发踩坑记录

Word count: 216Reading time: 1 min
2025/01/08
loading

UIButton

  1. UIButton 点击不生效的问题:

    1. 透明度,展示效果。

    2. userInteractionEnabled = YES

    3. 是否是顶层视图或者说是否被其他视图覆盖。

    4. 父视图是否是可以响应事件的。(比如加到一个UIImageView上面,UIImageView 需要设置userInteractionEnabled = YES)

  2. UIButton 设置内边距

    1
    2
    3
    // The effect of these properties can be replicated via UIButtonConfiguration.contentInset and UIButtonConfiguration.imageToTitlePadding. They are ignored when a configuration is set.
    @property(nonatomic) UIEdgeInsets contentEdgeInsets API_DEPRECATED("This property is ignored when using UIButtonConfiguration", ios(2.0,15.0), tvos(2.0,15.0), visionos(1.0, 1.0)) UI_APPEARANCE_SELECTOR API_UNAVAILABLE(watchos); // default is UIEdgeInsetsZero. On tvOS 10 or later, default is nonzero except for custom buttons.
    @property(nonatomic) UIEdgeInsets titleEdgeInsets API_DEPRECATED("This property is ignored when using UIButtonConfiguration", ios(2.0, 15.0), tvos(2.0, 15.0), visionos(1.0, 1.0)) API_UNAVAILABLE(watchos); // default is UIEdgeInsetsZero

    设置contentEdgeInsets 可以实现按钮宽度自适应撑开。

动图

apng 使用UIImageView 没办法控制只播放动画一次的效果。

CATALOG
  1. 1. UIButton
  2. 2. 动图