我對本地應用程序開發世界相當陌生,主要是前端開發人員/設計人員 - 我在Xcode 5中構建了一個IOS7應用程序 - 其中包含具有多個自定義單元格的UITable 。我想爲每個單元格添加大約8px的邊距(看起來像下面的圖像) - 並且改變通過push segue出現的鏈接箭頭的顏色 - 但是不知道如何做到或者儘管網頁很好搜索/讀書 - theres似乎不是故事板上的相關選項。將Margin添加到自定義UI表單元格
任何人都可以建議,如果可能?
我對本地應用程序開發世界相當陌生,主要是前端開發人員/設計人員 - 我在Xcode 5中構建了一個IOS7應用程序 - 其中包含具有多個自定義單元格的UITable 。我想爲每個單元格添加大約8px的邊距(看起來像下面的圖像) - 並且改變通過push segue出現的鏈接箭頭的顏色 - 但是不知道如何做到或者儘管網頁很好搜索/讀書 - theres似乎不是故事板上的相關選項。將Margin添加到自定義UI表單元格
任何人都可以建議,如果可能?
的代碼是這樣的方法:
- (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;
通過調整表格本身的大小,可以爲單元格添加邊距。而不是標準的320像素寬度,將表格的寬度更改爲312.這將爲您提供一個整體邊距,而不必介入表格視圖的內部。
CGFloat margin = 8;
self.tableView.frame = CGRectMake(0, 0, self.view.frame.width-margin, self.view.frame.height);
爲了改變箭頭的顏色,你必須改變什麼所謂的UITableViewCell
的accessoryView
。它可以是任何UIView
。
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coloredArrow.png"]];
對我來說,它工作在50更改名稱「細胞」 %:邊距被添加,但它們也覆蓋表格內容。因此,在我的情況下,我失去了在行左側的圓角。 –
感謝llario - 這是否會應用於每個自定義類或含表 – Dancer
@保羅這段代碼也適用於定製的電池,只需用customNameCell – Ilario