根据图片大小,自动设置按钮大小

根据图片大小,自动设置按钮大小。用(CGREC){CGPointZero,leftImage.size}强转

不要直接拿按钮文字,拿出来的是空的。因为按钮文字是分状态的。要用NSString *btnTitle = [btn titleForState:UIControlStateNormal

锚点anchorPoint和position。btn.layer.anchorPoint;btn.layer.position

//点击触发方法,pointInside和hitTest

 通过position定义可以知道position是layer中的anchorPoint点在superLayer中的位置坐标.position点是相对superLayer的.

anchorPoint是相对于自身layer,anchorPoint点(锚点)的值是用相对bounds的比例值来确定的

 

   /* Defines the anchor point of the layer's bounds rect, as a point in

     * normalized layer coordinates - '(0, 0)' is the bottom left corner of

     * the bounds rect, '(1, 1)' is the top right corner. Defaults to

     * '(0.5, 0.5)', i.e. the center of the bounds rect. Animatable. */

open var anchorPoint: CGPoint

 

 

https://www.jianshu.com/p/f9a83a72e274

图片拉伸

[image resizableImageWithCapInsets:UIEdgeInsetsMake(5555resizingMode:UIImageResizingModeStretch]; 

// 代表按钮变为UIControlStateDisabled状态

            share.enabled = NO;

// 设置分享按钮的选中状态是真

            share.selected = YES;            

// 按钮在高亮的时候不需要变灰色

            share.adjustsImageWhenHighlighted = NO;

            

原文地址:https://www.cnblogs.com/dengchaojie/p/4743352.html