有人可以告诉我最简单的方法来更改UITableView部分标题中文本的字体大小吗?
我使用以下方法实现了部分标题:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
然后,我了解如何使用此方法成功更改节标题高度:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
我使用此方法填充了UITableView单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何实际增加部分标题文本的字体大小 - 或者字体样式?
有人可以帮忙吗?谢谢.
我已经使用正确的委托和数据源链接设置了tableview .. reloadData方法调用数据源和委托方法,除了viewForHeaderInSection:.
为什么会这样?
这就是我现在所拥有的.
我如何参考这个,以便我可以更改文本颜色以匹配我的索引列表?该sectionForSectionIndexTitle运作良好的正确的章节标题添加,但究竟怎样一个接入标题元素?
或者它是不可能的,我需要重绘视图并使用viewForHeaderInSection添加它?
我遇到了自动/动态UITableView节头视图的问题,其中包含一个包装的UILabel(numberOfLines = 0).高度未正确计算,尤其是在滚动表格并重新使用视图后.有时UILabel包裹,有时它被截断,有时一个或多个标签不可见,有时标签之间有额外的间距.自定义视图包含一个带有三个UILabel的垂直UIStackView,其中一个包装.
可以在https://github.com/outerstorm/tableviewHeaderTest找到演示该问题的完整示例应用程序.
截面标题高度在viewDidLoad中设置为自动,具有以下内容:
tableView.sectionHeaderHeight = UITableViewAutomaticDimension
tableView.estimatedSectionHeaderHeight = 30.0
Run Code Online (Sandbox Code Playgroud)
并且还实现了以下heightForHeaderInSection,试图让它工作:
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return UITableViewAutomaticDimension
}
Run Code Online (Sandbox Code Playgroud)
我也尝试在各个点调用setNeedsLayout()和layoutIfNeeded()无济于事.任何建议将不胜感激.
以下是应用中看到的行为的屏幕截图.第一部分是截止的,第二部分太高了:
uitableview ios uitableviewautomaticdimension uitableviewsectionheader
我正在 UITableViewController 中实现可折叠的部分标题。
以下是我确定每个部分显示多少行的方法:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.sections[section].isCollapsed ? 0 : self.sections[section].items.count
}
Run Code Online (Sandbox Code Playgroud)
有一个结构体保存了带有“isCollapsed”布尔值的部分信息。
这是我如何切换他们的状态:
private func getSectionsNeedReload(_ section: Int) -> [Int]
{
var sectionsToReload: [Int] = [section]
let toggleSelectedSection = !sections[section].isCollapsed
// Toggle collapse
self.sections[section].isCollapsed = toggleSelectedSection
if self.previouslyOpenSection != -1 && section != self.previouslyOpenSection
{
self.sections[self.previouslyOpenSection].isCollapsed = !self.sections[self.previouslyOpenSection].isCollapsed
sectionsToReload.append(self.previouslyOpenSection)
self.previouslyOpenSection = section
}
else if section == self.previouslyOpenSection
{
self.previouslyOpenSection = -1
}
else
{
self.previouslyOpenSection = section
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用autolayout创建节标题.带标题和计数器的简单标题
class ProfilePeopleListHeaderViewCell: UIView {
let titleLeftOffset = 12
let counterRightOffset = 5
let counterWidth = 50
var title = "title" {
didSet {
titleLabel.text = title
}
}
var numberOfPeople = 0 {
didSet {
peopleCounter.text = "\(numberOfPeople)"
}
}
let titleLabel = UILabel()
let peopleCounter = UILabel()
convenience init(title: String, numberOfPeople:Int) {
self.init()
self.title = title
self.numberOfPeople = numberOfPeople
backgroundColor = UIColor.greenColor()
titleLabel.textColor = Constants.Colors.ThemeGreen
titleLabel.textAlignment = .Left
if #available(iOS 8.2, *) {
titleLabel.font = Constants.Fonts.Profile.PeopleListHeaderFont
peopleCounter.font = …Run Code Online (Sandbox Code Playgroud) 我使用Xib文件而不是故事板.我创建了一个包含一些虚拟数据的表视图.它的工作正常,现在我已经创建了一个带有一些标签和textFields的自定义单元格.如何将其用作UITableView的页眉或页脚?
我有浮动标题UITableView(我想要的).但是当UITextView上面单元格中的建议视图位于标题下时,它看起来很糟糕.
好像以前没有人遇到过这个问题.有什么建议?
标题单元格UITableViewCell都是从Xib加载的.
浮动标题在其第二个最顶层视图上有一个alpha,所以它有点透视.
这是它在"调试视图层次结构"中的外观:
UITableView我已经掌握了一些细胞的基础知识。我使用 SwiftUIView作为单元格和节标题的内容。奇怪的是,只有 iPhone XS Max 上似乎接触屏幕底部的部分标题似乎获得了rawSafeAreaInset16 分(检查了“调试视图层次结构”)。我的细胞正在按预期工作。
为了看看发生了什么,我在 中添加了一个虚拟的蓝色 SwiftUI 矩形contentView,然后在顶部放置了一个红色 UIView,两个视图都设置为相同的约束。已UITableView设置为对标题和单元格使用自动尺寸。
public class SectionHeader: UITableViewHeaderFooterView {
public static let reusableIdentifier = "Section"
private var innerHostedViewController: UIHostingController<AnyView>!
public override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
setupHeader()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupHeader() {
self.backgroundView = UIView()
self.backgroundView?.backgroundColor = UIColor.green.withAlphaComponent(0.2)
innerHostedViewController = UIHostingController(rootView: AnyView(Rectangle().fill(Color.blue).frame(height: 48)))
innerHostedViewController.view.translatesAutoresizingMaskIntoConstraints = false
innerHostedViewController.view.frame = self.contentView.bounds
contentView.addSubview(innerHostedViewController.view)
innerHostedViewController.view.backgroundColor = .clear …Run Code Online (Sandbox Code Playgroud) 如何使用自定义标题按节排列单元格
我已设置代码以按品牌排列CartVC中的单元格(将品牌放置在CartHeaderCell中)。当数据从HomeVC传递到CartVC时,我无法从我在CartVC中创建的代码中按品牌将单元格按节排列。(当前代码将数据从HomeVC传递到CartVC,而没有将单元格分成几部分)
数据传递到购物车后,如何在CartVC中按品牌排列部分
更新:
现在,代码中的代码CartViewController Extension将单元划分为多个部分,然后将各个项目按品牌传递到各个单元中,但是将所有单元加扰为随机部分,或者在单元中为该品牌创建一个新的部分,并且/或者当按下CartBtn,或在多个部分中显示相同的项目/单元格
extension HomeController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemSetup.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCell") as? HomeCell else { return UITableViewCell() }
let item = itemSetup[indexPath.row]
cell.configure(withItems: item)
// passes data to the Cart Cells in the CartVC when ATC Btn is pressed …Run Code Online (Sandbox Code Playgroud) ios ×9
uitableview ×8
swift ×7
arrays ×1
assert ×1
autolayout ×1
collapsable ×1
custom-cell ×1
objective-c ×1
swiftui ×1
tableview ×1