ios15 UITableView Section Label font size and color was change - uitableview

After upgrading ios14 to ios15, the font size and color of the label in the section of uitableview have changed.
click link view picture!
Is there any global solution.
My current method is like this, but I can only solve one tableview
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
header.textLabel.textColor = [UIColor colorWithRed:0.137f green:0.137f blue:0.137f alpha:1.0];
header.textLabel.font = [UIFont boldSystemFontOfSize:17];
NSLog(#"title size is %f",header.textLabel.font.pointSize);
}
LOG:
IOS14: title size is 17.000000
IOS15: title size is 15.000000

Related

How to adjust a UILabel placed under UITextView resized with autolayout?

I have an objective-c application and I'm using autolayout. I have a tableview, and the cells contains a UIImageView, a UITextView, another UIImageView and one UILabel added. Like:
I want keep whe cell with the image and label under textView, but when I run my app, the label and the image are on the textView...
I have this functions to apply an adjust to the content of UITextView depending of size and font of the text:
- (CGFloat)textViewHeightForAttributedText: (NSAttributedString*)text andWidth: (CGFloat)width {
UITextView *calculationView = [[UITextView alloc] init];
[calculationView setAttributedText:text];
CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
return size.height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UIFont *font = [UIFont systemFontOfSize:14.0];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:brokenCars[indexPath.row] attributes:attrsDictionary];
return [self textViewHeightForAttributedText:attrString andWidth:CGRectGetWidth(self.myTable.bounds)-31]+50;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
[cell setNeedsLayout];
[cell layoutIfNeeded];
...
}
//In the UITableViewCell:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
[self.myText sizeToFit];
[self.myText layoutIfNeeded];
CGSize size = [self.myText sizeThatFits:(CGSizeMake(self.myText.contentSize.width, FLT_MAX+30))];
[self.myText setContentSize:size];
}
And I have added this constraints:
To left first UIImageView:
To UITextView:
To second down UIImageView:
And to the UILabel:
What am I doing bad?
How can I move this and hold down the UITextView always?
Thanks!
EDIT 1:
Add this to more crearly. I want get this, always the label and image dwon of textview, but textView extended showing all text:
I'm showing all text extended but the image and label is on the text like fist picture.

How to update the color of section title without uitableview reloadData

I'm using willDisplayHeaderView to change the color of section title:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
header.textLabel.textColor = [UIColor grayColor];
}
Now, I want to update the color of a section title, how to do it without [tableview reloadData]?
There are two method in UITalbeView to get the headerView and footerView respectively:
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
Try this:
UITableViewHeaderFooterView *header = [self.tableView headerViewForSection:0];
header.textLabel.textColor = [UIColor redColor];

UICollectionViewCell UILabel with NSMutableAttributedString attributedText slow to update & display

Using iOS 8.1.2 on iPad & iPhone. I have UICollectionViewCells which are created with initWithCoder: from a xib and displayed in a UICollectionView with
[_collectionView registerNib:[UINib nibWithNibName:#"HomeFeedCell" bundle:nil] forCellWithReuseIdentifier:CELL_IDENTIFIER];
The template xib cell contains a UILabel with default attributed text. The cell is also set up to use autolayout constraints.
When the cell is instantiated & updated with its data I call the following method to update the attributed text:
- (void)setLabelsForData:(NSDictionary*)dict_data {
NSMutableAttributedString* attributedText_date = [[NSMutableAttributedString alloc] initWithString:[self dateStringForTimestamp:[dict_data objectForKey:#"ts"]]];
NSMutableAttributedString* attributedText_time = [[NSMutableAttributedString alloc] initWithString:[self timeStringForTimestamp:[dict_data objectForKey:#"ts"]]];
UIFont* font_date = [UIFont fontWithName:#"Helvetica-Bold" size:12.0];
UIFont* font_time = [UIFont fontWithName:#"Helvetica" size:12.0];
[attributedText_date addAttribute:NSFontAttributeName value:font_date range:NSMakeRange(0, attributedText_date.length)];
[attributedText_time addAttribute:NSFontAttributeName value:font_time range:NSMakeRange(0, attributedText_time.length)];
dateLabel.attributedText = attributedText_date;
timeLabel.attributedText = attributedText_time;
}
However when the UICollectionView is pushed modally, when the cells in view are initially displayed and each shows their UILabel's attributed text in its original xib default form for about 1 second before finally updating with the correct data & formatting. Once the UICollectionView has been shown though the UILables do not have this problem while scrolling through those cells and any new ones. Only initially on the visible ones upon the appearance of the UICollectionView.
I have tried:
[cell setNeedsDisplay];
[cell setNeedsLayout];
[collectionView invalidateLayout];
at the end of the method. I have even put the whole method on the main thread hoping it was a thread issue, but no luck.
What could be causing the slow update of the UILabel?
Its a bit late but seems that I have the same problem the easiest solution for me was to update the UILabel in
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
(this method is available in IOS 8 and up).
I also encounter the same problem with UITableView
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

How to change index based section common color in UITableView

Normally my screen display is like this:
When I use this code
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[headerView setBackgroundColor:[UIColor whiteColor]];
return headerView;
}
my output is like this:
My section index text is not visible. I know that the section header view add my custom view. I want to change section header color and also display index text.
#Khawar answer i get this output
this is work 100% and you can change your index or header text color
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
view.tintColor = [UIColor blueColor];
// if you have index/header text in your tableview change your index text color
UITableViewHeaderFooterView *headerIndexText = (UITableViewHeaderFooterView *)view;
[headerIndexText.textLabel setTextColor:[UIColor blackColor]];
}
output:
Try to set the height for UITableView header.
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30.0;
}
If you only need to change the background color of section header while displaying section title, you don't need to create custom view for that. Custom view would overwrite your default header and your title would not be shown, unless you add custom UILabel in your custom view. Just use following UITableView delegate to change background color.
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
view.tintColor = [UIColor redColor];
}
See results before and after.
----------------Before------------------
----------------After------------------
Hope this fixes the issue.
You have to give title for section... Or you can use this method..
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *headerView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[headerView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.5]];
headerView.text = [self tableView:tableView titleForHeaderInSection:section];
return headerView;
}

UITableView Background Image for Static Section/Cells

I know we can add background images/colors to section headers in dynamic table view/cells but can anyone help me do the same in a table view using Static Cells ?
What I want to do is use a background image for my 3rd section in a TableView which is using static cells (total of 4 sections it has)
I want to add a background image and change text color to say some RGB value for the 3rd section
You can use the delegate methods of UITableView to set the height and view for a section header. This should do what you want:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return (section == 2)? 100:30;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 100)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 100)];
label.text = #"Description";
label.textColor = [UIColor whiteColor];
[imageView addSubview:label];
imageView.image = [UIImage imageNamed:#"House.tiff"];
return (section == 2)? imageView:nil;
}
UITableViewCells have the backgroundView property which is a UIView. You can change that to be a UIImageView, for example, or build a more complex background for you table view cells. It shouldn't matter, whether the cell is static or dynamic.
The text color for the cell can then simply be changed by setting the UITableViewCells cell.textLabel.textColor.
Same applies for the UITableViewHeaderFooterView, which are (as the name says) used for the header and footer of your table view sections. In code, you can access the header for a section using
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section
This saves you from completely recreating the header from scratch, just to make small adjustments. Alternatively, override
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and build a custom UIView that will become your header.
You should assign a tag(say 15) to the static cell in
tableview:didSelectRowForIndexPath
and then
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(cell.tag==15)
cell.backgroundColor = [UIColor colorWithRed:255/255.0 green:250/255.0 blue:243/255.0 alpha:1.0];
}

Resources