简体   繁体   中英

iOS - UILabel + UIActivityIndicatorView inside UITableView section header

In the Settings app when you select a Wi-Fi network you can see a table view that has a label and an activity indicator right after the label. Is there some predefined way to create such a UI. Or the only way to do it is to implement the tableView:viewForHeaderInSection with some code that creates a label and a spinner, calculates the label width and places the spinner right after it?

Yes, you have the right approach! Create a header view with a label and place an UIActivityIndicator right after it. The calculation is pretty simple:

UILabel* myLabel = ...;
CGSize size = [myLabel.text sizeWithFont: myLabel.font];

UIActivityIndicator* indicatorView = ...;
indicatorView.center = CGPointMake(size.width + indicatorView.frame.size.width, myLabel.center.y);

UITableViewCell.accessoryView,创建一个UIActivityIndi​​cator实例并分配给它。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM