2013-10-15 142 views
1

我对本地应用程序开发世界相当陌生,主要是前端开发人员/设计人员 - 我在Xcode 5中构建了一个IOS7应用程序 - 其中包含具有多个自定义单元格的UITable 。我想为每个单元格添加大约8px的边距(看起来像下面的图像) - 并且改变通过push segue出现的链接箭头的颜色 - 但是不知道如何做到或者尽管网页很好搜索/读书 - theres似乎不是故事板上的相关选项。将Margin添加到自定义UI表单元格

任何人都可以建议,如果可能?

enter image description here

回答

2

的代码是这样的方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

针对每个小区的附加裕度(此代码只给每个小区的顶部添加余量):

UIView *separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 8)]; 
separatorLineView.backgroundColor = [UIColor redColor]; 
[cell.contentView addSubview:separatorLineView]; 

和对于箭头颜色,您必须创建一个图像并将其与此代码一起插入:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 7, 11)]; 
[label setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"yourimage.png"]]]; 
cell.accessoryView = label; 
+0

感谢llario - 这是否会应用于每个自定义类或含表 – Dancer

+0

@保罗这段代码也适用于定制的电池,只需用customNameCell – Ilario

2

通过调整表格本身的大小,可以为单元格添加边距。而不是标准的320像素宽度,将表格的宽度更改为312.这将为您提供一个整体边距,而不必介入表格视图的内部。

CGFloat margin = 8;  
self.tableView.frame = CGRectMake(0, 0, self.view.frame.width-margin, self.view.frame.height); 

为了改变箭头的颜色,你必须改变什么所谓的UITableViewCellaccessoryView。它可以是任何UIView

cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coloredArrow.png"]]; 
+0

对我来说,它工作在50更改名称“细胞” %:边距被添加,但它们也覆盖表格内容。因此,在我的情况下,我失去了在行左侧的圆角。 –

相关问题