图片拉升不变形,类似聊天气泡

//标签1

CGSize sizeLabel1 = [[NSString stringWithFormat:@"#%@",arrayFrom[k][@"label"]] sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20.0*HeightProportion]}];

UIButton * buttonLabel1 = [UIButton buttonWithType:UIButtonTypeCustom];

buttonLabel1.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);

[buttonLabel1 setBackgroundImage:[self resizableImageWithName:@"拉伸标签"] forState:UIControlStateNormal];

[buttonLabel1 setTitle:[NSString stringWithFormat:@"#%@",arrayFrom[k][@"label"]] forState:UIControlStateNormal];

[buttonLabel1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

buttonLabel1.titleLabel.font = [UIFont systemFontOfSize:20.0*HeightProportion];

//汉字内部距离

[buttonLabel1 setTitleEdgeInsets:UIEdgeInsetsMake(0, 15.0*WidthProportion, 0, 20)];

[imagePhone addSubview:buttonLabel1];

//图片拉升不变形

- (UIImage *)resizableImageWithName:(NSString *)name{

UIImage *oldImage = [UIImage imageNamed:name];

//    resizableImageWithCapInsets:设定拉伸范围(让图片距离上左下右有多少范围不拉伸)

//    resizingMode:表示拉伸的方法。

CGFloat w = oldImage.size.width * 0.5;

CGFloat h = oldImage.size.height * 0.5;

return [oldImage resizableImageWithCapInsets:UIEdgeInsetsMake(h, w, h, w) resizingMode:UIImageResizingModeStretch];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 打印View所有子视图 layoutSubviews调用的调用时机 当视图第一次显示的时候会被调用当这个视图显示到...
    hyeeyh阅读 3,529评论 0 3
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,359评论 1 14
  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 9,209评论 2 7
  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 4,818评论 1 6
  • 1.NSString过滤特殊字符串定义一个特殊字符的集合NSCharacterSet set = [NSChara...
    奋拓达阅读 4,221评论 0 0

友情链接更多精彩内容