UITableViewHeaderFooterView: Unable to change background color

前端 未结 20 2223
误落风尘
误落风尘 2020-12-23 08:38

I\'m trying to change the background color of UITableViewHeaderFooterView. Although the view is appearing, the background color remains the default color. I\'m getting a log

20条回答
  •  一生所求
    2020-12-23 09:19

    I feel compelled to share my experience. I had this piece of code that worked fine with iOS 10 and iOS 11 headerView?.contentView.backgroundColor = .lightGray

    Then I all of a sudden decided to to deploy the app for iOS 9 as there are some devices (iPad mini some older generation doesn't update to any OS beyond 9) - The only solution that worked for all iOS 9, 10 and 11 was to define a base view for the header that then contains all other header subviews, wire it up from storyboard and set the backgroundColor of that base view.

    You will want to be mindful when wiring the outlet not to call it: backgroundView as there is already a property with that name in some superclass. I called mine containingView

    Also when wiring the outlet control click on the view in Document Outline to make sure it's not wired up to file owner

提交回复
热议问题