preface

It’s currently based on XCode13 beta, iOS15. Maybe apple has a conscience and the back automatically works.

NavigationBar color and background invalid

- (void)viewDidLoad { [super viewDidLoad]; [self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor redColor]] forBarMetrics:UIBarMetricsDefault]; } - (UIImage *)imageWithColor:(UIColor *)color {CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }Copy the code

🤔 above is the demo code, the intention is to set a background image for the navigation bar, the image is generated by the color (business scene needs, you can directly set barTintColor or normal background image)

😭 However, good code in XCode13 beta,iOS 15 directly gg

UINavigationBarAppearance *app = [UINavigationBarAppearance new];
[app configureWithOpaqueAppearance];
app.backgroundColor = UIColor.redColor;
navigationBar.scrollEdgeAppearance = app
navigationBar.standardAppearance = app;
Copy the code

Later search fruitless, went to apple forum feedback, and then got the feedback above.

Details can see developer.apple.com/forums/thre…

😄 is a simple way to set up apperance using the new API in iOS13. I think it’s a bit buggy and I had to set a scrollEdgeAppearance to make it work. According to apple’s official documentation, standardAppearance is automatically used if scrollEdgeAppearance is nil. But I’m just a developer…

Tableview Header section set to 0 is invalid

self.tableView = [[UITableView alloc] initWithFrame:self.view.frame]; - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UILabel *label = [[UILabel alloc] init]; label.text = @"test"; return label; } - CGFloat tableView: (UITableView *) tableView heightForHeaderInSection: (NSInteger) section {return 0.01; }Copy the code

🤬 code is roughly like this, is also a demo. 0.01 literally how to change all have no egg use.

I looked at the API changes later

I found one of these

var sectionHeaderTopPadding: CGFloat { get set }
Copy the code

And then directly

If (@ the available (iOS 15.0, *)) {_tableView. SectionHeaderTopPadding = 0; }Copy the code

😂 the world is clean, but I feel that the follow-up change will repair, this thing is too pit…

conclusion

👨🏻💻 For now, step on these two pits. New ones will be sent out later. You are also welcome to comment on the new pit. Then there are two good methods: 1. Apple forum post, my first question was answered by Apple employees 2. Take a look at the API update documentation, where updates are noted.