当前位置: 首页 > news >正文

织梦 网站栏目管理企业注册信息查询单怎么打印

织梦 网站栏目管理,企业注册信息查询单怎么打印,推广软件哪个好,成都便宜网站建设公司自定义按钮UIControl 写在前面 #图标和文字在一起是开发难免的问题#xff0c;系统的按钮默认是图片居左的文字居右的#xff0c; 且图片和文字的距离不好调整#xff0c;图片的位置更是让人头疼#xff0c; 故在闲暇之余封装了一个控件。 复制代码所用到知识的 # 1、苹果系…自定义按钮UIControl 写在前面 #图标和文字在一起是开发难免的问题系统的按钮默认是图片居左的文字居右的 且图片和文字的距离不好调整图片的位置更是让人头疼 故在闲暇之余封装了一个控件。 复制代码所用到知识的 # 1、苹果系统自带的自动布局减少第三方的依赖 # 2、kvo监听UIControl的状态 # 3、富文本的使用如何更新约束如何获取一段文字的宽高复制代码先看看效果 拥有功能 1、任意调整图片和文字的间距。 2、图片的位置可以放置在上下左右不同位置。 3、支持富文本自定义布局高亮和选中状态。 复制代码如何使用 /**自定义按钮初始化方法param image 默认的图片param title 标题param titleFond 标题大小param imageMargin 标题与图标的距离param imageAlignmentTYpe 图片的显示类型return 自定义按钮的实例*/ - (instancetype)initWithImage:(UIImage *) imagetitle:(NSString *) titletitleFond:(UIFont *) titleFondimageMargin:(CGFloat) imageMarginimageAlignmentTYpe:(MyButtonImageAlignmentTYpe )imageAlignmentTYpe;_myButton [[MyButton alloc]initWithImage:[UIImage imageNamed:cache_pause]title:来点我啊titleFond:[UIFont systemFontOfSize:14]imageMargin:10imageAlignmentTYpe:MyButtonImageAlignmentLeft];[self.view addSubview:_myButton];self.myButton.frame CGRectMake(20, 100, 120, 40);self.myButton.backgroundColor UIColor.grayColor;[self.myButton setImage:[UIImage imageNamed:cache_delete] withState:UIControlStateSelected];[self.myButton setImage:[UIImage imageNamed:cache_pause] withState:UIControlStateHighlighted];[self.myButton setTitle:选中了 withState:UIControlStateSelected];[self.myButton setTitle:正在按下... withState:UIControlStateHighlighted];[self.myButton setTitleColor:UIColor.blueColor withState:UIControlStateSelected];[self.myButton setTitleColor:UIColor.yellowColor withState:UIControlStateHighlighted];这样就可以了和普通的按钮用法一样。复制代码关键代码 1、自定义布局只列出了一种 //图片居左 - (void)setImageLeftLayoutConstraint {CGFloat imageWidth self.normalImage.size.width;CGFloat titleWidth [self sizeWithText:self.titleLabel.text font:self.titleLabel.font].width;CGFloat imageCenterXMargin (imageWidth /2.0 - (imageWidth titleWidth self.imageMargin) / 2.0);//创建Image约束NSLayoutConstraint *imageCenterYLc [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];NSLayoutConstraint *imageCenterXLc [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:imageCenterXMargin];[self addConstraints:[imageCenterYLc,imageCenterXLc]];//创建title约束NSLayoutConstraint *titleCenterYLc [NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];NSLayoutConstraint *titleLeftLc [NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.imageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:self.imageMargin];[self addConstraints:[titleCenterYLc,titleLeftLc]]; }//获取文字的宽高 - (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font {NSDictionary *attrs {NSFontAttributeName : font};return [text boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size; }//kvo监听 - (void)addObserver {[self addObserver:selfforKeyPath:enabledoptions: NSKeyValueObservingOptionNewcontext:nil];[self addObserver:selfforKeyPath:selectedoptions: NSKeyValueObservingOptionNewcontext:nil];[self addObserver:selfforKeyPath:highlightedoptions: NSKeyValueObservingOptionNewcontext:nil];[self.titleLabel addObserver:selfforKeyPath:textoptions:NSKeyValueObservingOptionNewcontext:nil]; }//kvo 监听处理只列出了部分 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionaryNSKeyValueChangeKey,id *)change context:(void *)context {if ([keyPath isEqualToString:selected]) {if(self.selected) {self.imageView.image self.selectedImage ? self.selectedImage : self.normalImage;self.backgroundColor self.selectedBackgroundColor ? self.selectedBackgroundColor : self.normalBackgroundColor;if (!self.selectedTitleAttribute !self.normalTitleAttribute) {self.titleLabel.text self.selectedTitle ? self.selectedTitle : self.normalTitle;self.titleLabel.textColor self.selectedTitleColor ? self.selectedTitleColor : self.normalTitleColor;return;}self.titleLabel.attributedText self.selectedTitleAttribute ? self.selectedTitleAttribute : self.normalTitleAttribute;} else {self.imageView.image self.normalImage;self.backgroundColor self.normalBackgroundColor;if (!self.normalTitleAttribute) {self.titleLabel.text self.normalTitle;self.titleLabel.textColor self.normalTitleColor;return;}self.titleLabel.attributedText self.normalTitleAttribute;}} //监听到字体变化更新自动布局if ([keyPath isEqualToString:text]) {[self removeConstraints:self.constraints];[self.superview layoutIfNeeded];[self updateConstraints:self.imageAlignmentTYpe];[self.superview layoutIfNeeded];} 复制代码以上只是部分代码详细代码请查看 欢迎查看MyApp 自定义按钮 https://github.com/dudongge/MyApp 如果对您有帮助请不吝star一下
http://wiki.neutronadmin.com/news/117761/

相关文章:

  • 第三方开放平台有哪些网络seo啥意思
  • 制作个人博客网站个人网站建设知乎
  • 优秀的店面空间设计网站网站数据库建设计划书
  • 网站建设优化服务资讯烟台开发区建设业联合会网站
  • flash网站开发教程潍坊网站建设 潍坊做网站
  • oss做网站网架结构厂家
  • 用百度云服务器做网站seo怎么做
  • 域名建网站公司网页设计入门与应用电子书pdf百度网盘
  • 两学一做 网站源码区域工业互联网平台
  • 旅游网站建设经费预算运动分类的网站设计论文
  • 网站外贸推广html5网站设计
  • 上虞宇普电器网站建设农业网站建设策划书
  • 做百度网站接到多少客户电话号码建设个网站需要什么
  • 网站建设 百度文库门户网站的布局
  • 好网站开发策划要求建设银行不良资产处置网站
  • 玩具网站建设方案企业网站源码变现方法
  • 网站开发工程师薪酬待遇华为公司网站建设相关内容
  • 湘潭网站建设问下磐石网络国际数据公司idc
  • wordpress手机端底部按钮长沙网站排名优化费用
  • 建设网站要钱吗pc网站开发使用什么布局好
  • 深圳网站制作公司兴田德润官网多少招聘网站内容建设
  • 上海做原创网站网站开发 脚本之家
  • 查找邮箱注册过的网站福建省建设厅网站节能办
  • 深圳网站美化福州房产网站建设
  • 东莞齐诺做网站网络市场调研的步骤
  • 济宁网站建设 水木网站怎么更改关键词
  • 网站建设费用计入哪个科目网站空间 价格
  • 北京好的建站团队专业做网站服务
  • 福州服务类网站建设快站淘客中转页
  • 广州外贸网站制作营销型网站的三元素