小编Jp4*_*eal的帖子

使用标头数组更改UITableView中的节标题背景颜色

我有一个我使用的标头数组

let sectionHeaderTitleArray = ["test1","test2","test3]
Run Code Online (Sandbox Code Playgroud)

他们被展示使用

func tableView[tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.sectionHeaderTitleArray[section] as String
} 
Run Code Online (Sandbox Code Playgroud)

现在所有这一切工作正常,但我想修改标题的背景颜色,使它们更加明显(深色)

任何想法,如果我可以在一个简单的行中这样做或我需要使用自定义单元格来创建它

谢谢

更新

  //number of sections and names for the table

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return self.sectionHeaderTitleArray.count
    }

    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return self.sectionHeaderTitleArray[section] as String
    }
    func tableView(tableView: UITableView, ViewForHeaderInSection section: Int) -> UIView? {
        return self.tableView.backgroundColor = UIColor.lightGrayColor()
    }
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift ios8

45
推荐指数
6
解决办法
4万
查看次数

点击时可以打开和关闭UITableViewCell复选标记

我正在做一个tableview

我希望能够点击每个单元格,当点击时,它会在单元格上显示一个复选标记

现在我有一些代码可以使这个工作:

// checkmarks when tapped

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let section = indexPath.section
    let numberOfRows = tableView.numberOfRowsInSection(section)
    for row in 0..<numberOfRows {
        if let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: section)) {
            cell.accessoryType = row == indexPath.row ? .Checkmark : .None
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是这段代码只选择了一个区域内的1个单元格(我有5个区域)

我需要它在任何地方选择任何细胞

此外,当我上下拖动屏幕时,我会以复选标记丢失

viewcontroller.swift

class ViewController: UIViewController, UITableViewDataSource {                        //class and subclass                  |)
//---------------------------------------------------------------------------------------------------------------------------/
    // Variable and constant, also IBAOutlet

    let section1 =
       ["this is used",
        "this is used to test",
        "this …
Run Code Online (Sandbox Code Playgroud)

uitableview checkmark ios swift

41
推荐指数
6
解决办法
6万
查看次数

在iOS 8和swift中更改UITableViewCell字体

我正在尝试更改我的uitableviewcells的字体,

我目前正试图使用​​这个并没有成功:

cell.textLabel.font = [UIFont .preferredFontForTextStyle("Avenir")];
Run Code Online (Sandbox Code Playgroud)

现在我已经阅读了很多内容,似乎我应该使用它:

    cell.textLabel.font = [UIFont fontWithName: "Avenir" size:22];
Run Code Online (Sandbox Code Playgroud)

问题是在iOS 8中似乎不存在fontWithName

有任何想法吗??

谢谢

cell uitableview ios swift ios8

16
推荐指数
1
解决办法
1万
查看次数

iOS 10,UIToolbar背景颜色不会改变

我有一个应用程序,自iOS 8以来一直存在.它的工作方式是你有一个UITableView并点击单元格来产生一个分数,取决于底部的UI工具栏使用此方法改变颜色的分数:

func updateToolbarAndLabel(score: Int) {

    if(score <= -1) {
        self.toolbar.backgroundColor = UIColor.greenColor()
    } else if(score <= 0) {
        self.toolbar.backgroundColor = .None
    } else if(score <= 9) {
        self.toolbar.backgroundColor = UIColor.greenColor()
    } else if(score <= 29) {
       self.toolbar.backgroundColor = UIColor.yellowColor()
    } else if(score >= 30) {
        self.toolbar.backgroundColor = UIColor.redColor()
    }
    if (score <= 0) {
        self.scoreshow.text = "0"
    } else {
        self.scoreshow.text = (score as NSNumber).stringValue }
}
Run Code Online (Sandbox Code Playgroud)

然后每当用这个点击表格视图时调用它:

func tableView(tableView:UITableView,didSelectRowAtIndexPath indexPath:NSIndexPath){

事情是,它自从我构建应用程序以来一直有效,但在iOS 10上,它没有.简单地把颜色改变了......

任何帮助,将不胜感激

uitableview uitoolbar ios swift ios10

7
推荐指数
2
解决办法
6604
查看次数

标签 统计

ios ×4

swift ×4

uitableview ×4

ios8 ×2

cell ×1

checkmark ×1

ios10 ×1

uitoolbar ×1