解决方案 »
- memory 内存问题 uitableviewcell
- 怎么在其他方法里给UITableView cell上添加按钮?
- 对图片加入特定水印的方法
- Object_C和C++什么关系
- ios apns心跳抓包
- 关于NSBundle.pathForResource()取本地文件路径问题
- ios,安卓上传图片到我的java后台服务器中,就出现了下面的问题,我用电脑模拟测试没问题,可手机端传的时候就不行,找了好久,求大神赐教!!!
- ios 从一个界面传多个文本框的值给另一个界面
- 关于IOS APP推送
- CABasicAnimation为何不重复执行动画?
- 急急急急急!!!!熟悉xcode SVN的进
- oc,为什么简单的方法继承会报错?
{
self.backgroundColor = [UIColor whiteColor];
self.accessoryType = UITableViewCellAccessoryNone;
self.accessoryView = nil;
self.selectionStyle = UITableViewCellSelectionStyleNone;
// Fix for contentView constraint warning
[self.contentView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
// Create our ImageView
self.sampleImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
self.sampleImageView.translatesAutoresizingMaskIntoConstraints = NO;
self.sampleImageView.contentMode = UIViewContentModeScaleAspectFit;
self.sampleImageView.layer.borderColor = [UIColor colorWithWhite:210.0/255 alpha:1.0].CGColor;
self.sampleImageView.layer.borderWidth = 0.5;
self.sampleImageView.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:self.sampleImageView];
// title label
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.titleLabel.font = [UIFont systemFontOfSize:15];
self.titleLabel.textColor = [UIColor colorWithRed:50.0/255 green:50.0/255 blue:50.0/255 alpha:1.0];
self.titleLabel.numberOfLines = 1;
//self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
[self.contentView addSubview:self.titleLabel];
//discass label
self.discassLabel = [[UILabel alloc]initWithFrame:CGRectZero];
self.discassLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.discassLabel.font = [UIFont systemFontOfSize:12];
self.discassLabel.textColor = [UIColor grayColor];
self.discassLabel.numberOfLines = 1;
[self.contentView addSubview:self.discassLabel];
//discass image view
self.disImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
self.disImageView.translatesAutoresizingMaskIntoConstraints = NO;
self.disImageView.contentMode = UIViewContentModeScaleAspectFill;
self.disImageView.backgroundColor = [UIColor clearColor];
//self.disImageView.image = [UIImage imageNamed:@"comment.png"];
[self.contentView addSubview:self.disImageView];
CGFloat width = CGRectGetWidth([UIScreen mainScreen].bounds) - 22;
CGFloat height = width*18.0/29.0; // Constrain
NSDictionary *viewDict = NSDictionaryOfVariableBindings(_sampleImageView,_titleLabel,_disImageView,_discassLabel);
// Create a dictionary with buffer values
NSDictionary *metricDict = @{@"sideBuffer" : @11, @"verticalBuffer" : @6, @"midBuffer" : @5, @"imageWidth" : [NSNumber numberWithFloat:width],@"imageHeight" : [NSNumber numberWithFloat:height],@"smallicon" : @15};
// Constrain elements horizontally
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-sideBuffer-[_sampleImageView(imageWidth)]" options:0 metrics:metricDict views:viewDict]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_disImageView(smallicon)]-midBuffer-[_discassLabel]-smallicon-|" options:0 metrics:metricDict views:viewDict]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-smallicon-[_titleLabel]-(50)-|" options:0 metrics:metricDict views:viewDict]];
// Constrain elements vertically
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-verticalBuffer-[_sampleImageView(imageHeight)]" options:0 metrics:metricDict views:viewDict]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_disImageView(sideBuffer)]" options:0 metrics:metricDict views:viewDict]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.sampleImageView attribute:NSLayoutAttributeBottom multiplier:1 constant:5]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.disImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.titleLabel attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.discassLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.titleLabel attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
[self.discassLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
[self.disImageView setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
[self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
}
动态自动布局你可以这样,不懂的方法自己百度....