I want to change a label color on a specific cell in a tableview (by code). The problem is that I want to use a dynamic cell which result in that every label in every cell will have changed they colors. Is this possible? I would really appreciate some help. This is in xcode with Swift.
In your UITableViewDataSource
you can use tableView:cellForRowAtIndexPath:
to update that cell at a specific indexPath
, eg
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:YourCellIdentifier forIndexPath:indexPath]
if ([indexPath isEqual:theSpecificIndexPath]) {
cell.label.textColor = ...;
}
}
I would change it in willDisplayCell
:
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
// put your logic here and then change the color as appropriate, for instance:
let row = indexPath.row
switch row {
case 0:
cell.label.color = red // pseudo code
case 2:
cell.label.color = green // pseudo code
// etc
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.