iOS 使用可缩放图像的自定义按钮

来源:互联网 发布:摩托车车架号网络查询 编辑:程序博客网 时间:2024/05/21 17:23

iOS 使用可缩放图像的自定义按钮

也即是说,我们保证缩放图像的边缘位置保持图片的不变,而中间位置则跟随btn进行变化,利用这种功能可将图像用于尺寸的不同的按钮,而不会导致图像边缘发生扭曲。

    UIImage *btnBackImage = [UIImage imageNamed:@"msi_lol"];    CGFloat topInset = 10.0f;    CGFloat bottomInset = 10.0f;    CGFloat leftInset = 10.0f;    CGFloat rightInset = 10.0f;    UIEdgeInsets edgeInsets = UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset);    UIImage *stretchImage = [btnBackImage resizableImageWithCapInsets:edgeInsets];    [self.customBtn setBackgroundImage:stretchImage forState:UIControlStateNormal];
0 0