UITableViewHeaderFooterView的使用+自己主动布局

使用UITableView的header或footer复用时,假设採用自己主动布局,你会发现有约束冲突,以下这样写能够消除约束冲突:

#import <UIKit/UIKit.h>



@interface SectionView : UITableViewHeaderFooterView



@property (nonatomic, copy) NSString *sectionTitle;



@end

#import "SectionView.h"



@interface SectionView ()

{

    UIImageView *titleBgImageView;

    UIImageView *timePonitImageView;

    UIImageView *circleImageView;

    UILabel *titleLabe;

}

@end



@implementation SectionView



// 带有复用

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier

{

    self = [super initWithReuseIdentifier:reuseIdentifier];

    if (self) {

        [self createUI];

    }

    return self;

}





- (void)createUI

{

    titleBgImageView = [[UIImageView alloc] initForAutoLayout];

    titleBgImageView.userInteractionEnabled = NO;

    UIImage *image = [UIImage imageNamed:@"event_bottom_line"];

    image = [image stretchableImageWithLeftCapWidth:image.size.width*0.5 topCapHeight:image.size.height*0.5];

    titleBgImageView.image = image;

    [self.contentView addSubview:titleBgImageView];

    

    

    circleImageView = [[UIImageView alloc] initForAutoLayout];

    UIImage *circleImage = [UIImage imageNamed:@"event_blue1"];

    circleImage = [circleImage stretchableImageWithLeftCapWidth:circleImage.size.width*0.5 topCapHeight:circleImage.size.height*0.5];

    

    circleImageView.image = circleImage;

    [self.contentView addSubview:circleImageView];



    

    timePonitImageView = [[UIImageView alloc] initForAutoLayout];

    timePonitImageView.image = [UIImage imageNamed:@"event_write_line"];

    [self.contentView addSubview:timePonitImageView];

    

    

    titleLabe = [[UILabel alloc] initForAutoLayout];

    titleLabe.font = [UIFont systemFontOfSize:13];

    titleLabe.textColor = [UIColor whiteColor];

    titleLabe.textAlignment = NSTextAlignmentCenter;

    [circleImageView addSubview:titleLabe];

   

}



把布局代码写到这里

- (void)layoutSubviews

{

    [super layoutSubviews];

    

    [titleBgImageView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

    

    [circleImageView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:8];

    [circleImageView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:8];

    [circleImageView autoSetDimension:ALDimensionHeight toSize:23];

    [circleImageView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];

    

    [timePonitImageView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:16];

    [timePonitImageView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:39/2.0-4];

    [timePonitImageView autoSetDimensionsToSize:CGSizeMake(9, 23.5)];

    

    [titleLabe autoCenterInSuperview];

    [titleLabe autoSetDimension:ALDimensionWidth toSize:200];

    

}

UITableViewHeaderFooterView的使用+自己主动布局的更多相关文章

  1. IOS不用AutoLayout也能实现自己主动布局的类(3)----MyRelativeLayout横空出世

    对于IOS开发人员来说,在自己主动布局出现前仅仅能通过计算和设置frame的值来处理.这样设置位置时就会出现非常多硬编码,同一时候在屏幕旋转和不同屏幕之间适配时须要编码又一次调整位置和尺寸,我们也能够 ...

  2. iOS_ScrollView的自己主动布局

    ScrollView的自己主动布局稍显麻烦.但也是有规律可循, 下面就是仅竖向滑动的scrollView加入约束的固定做法 1.在控制器的view加入一个label.取名做anchor 2.给anch ...

  3. 他们主动布局(autolayout)环境的图像编辑器

    hi,all: 在经过了一番犹豫之后.我决定将我自己做的这个小APP的源代码发布给大家: 其出发点是和大家一起学习iOS开发.仅供学习參考之用. 之前代码是托管与gitlab 上的,今天我将其pull ...

  4. iOS 自己主动布局教程

    springs和struts的问题 你肯定非常熟悉autosizing masks-也被觉得是springs&struts模式.autosizing mask决定了当一个视图的父视图大小改变时 ...

  5. CSS3 网格布局(grid layout)基础知识 - 隐式网格自己主动布局(grid-auto-rows/grid-auto-columns/grid-auto-flow)

    网格模板(grid-template)属性及其普通写法(longhands)定义了一个固定数量的轨道.构成显式网格. 当网格项目定位在这些界限之外.网格容器通过添加隐式网格线生成隐式网格轨道. 这些隐 ...

  6. Fragment为载体可自己主动布局的CardView(GitHub上写开源项目初体验)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 前些天一直在看Android5.0 的Material Desgin,里面新增 ...

  7. 【iOS开发-48】九宫格布局案例:自己主动布局、字典转模型运用、id和instancetype差别、xib反复视图运用及与nib关系

    本次九宫格案例: (1)导入app.plist和各种图片素材,方便兴许开发.实际开发中,也是如此. (2)把plist中数组导入进来. --由于本案例中app.plist终于是一个数组,数组里面是字典 ...

  8. IOS自己主动布局中的浮动布局(6)----MyFloatLayout横空出世

    https://github.com/youngsoft/MyLinearLayout 前言 在MyLayout的6大布局中,每种布局都有不同的应用场景. 且每种布局的子视图的约束机制不一样:线性布局 ...

  9. NSLayoutConstraint-代码实现自己主动布局的函数使用方法说明

    [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelat ...

随机推荐

  1. 关于MyEclipse启动时的插件启动(Maven4MyEclipse)

    在myEclipse的应用中有许多插件在开发的时候都用不到,那么,这些插件在启动myEclipse的时候一起启动的越少越好了 Maven4Myeclipse update 每当启动myEclipse的 ...

  2. r语言之生成随机序列,随机数生成函数及用法

    (1)生成正态分布随机数: rnorm(n,mean,sd)     其中,n表示生成的随机数个数,mean表示正态分布均值,sd表示正态分布标准差 > rnorm(5,0,2)[1] -5.3 ...

  3. Introduction to Guid ( globally unique identifier )

    什么是 GUID? 全球唯一标识符 (GUID) 是一个字母数字标识符,用于指示产品的唯一性安装. 在许多流行软件应用程序(例如 Web 浏览器和媒体播放器)中,都使用 GUID. GUID 的格式为 ...

  4. Windows Phone 8初学者开发—第11部分:设置SounBoard应用程序

    原文 Windows Phone 8初学者开发—第11部分:设置SounBoard应用程序 原文地址: http://channel9.msdn.com/Series/Windows-Phone-8- ...

  5. 虽然net人

    http://v.qq.com/boke/page/c/h/0/c01173tzeh0.html http://v.qq.com/boke/page/r/7/x/r0117l07r7x.html ht ...

  6. 国际名品SYSTEM入驻北京金融街购物中心__购物败家_YOKA时尚网

    国际名品SYSTEM入驻北京金融街购物中心__购物败家_YOKA时尚网 国际名品SYSTEM入驻北京金融街购物中心

  7. Linux下批量转换文件编码

    find -iname "*.java" -exec enca {} + |grep -v ASCI |grep -v -i utf |awk -F':' '{print $1}' ...

  8. Ajax,设置默认焦点以及判断是否为空

    <style type="text/css"> .tishi{ color: red; } </style> <script type="t ...

  9. 安装帝国CMS遇到“修改php.ini,将:short_open_tag 设为 On”的解决方法+“建立目录不成功!请检查目录权限”问题

    想用安装个帝国CMS来做个网站,于是下载了程序,上传到服务器上,但是在输入安装路径的时候却给出了如下图示: 您的PHP配置文件php.ini配置有问题,请按下面操作即可解决: 1.修改php.ini, ...

  10. [转]Windows7 64bit下配置Apache+PHP+MySQL

    原文链接:http://blog.csdn.net/sbz0409/article/details/12946375 1.准备资料: 首先下载文件:Apache2.4.16 64bit,http:// ...