2017-04-17 60 views
-2

改變顯示工具欄菜單的字體大小對於下面的圖片:從編程迅速

enter image description here

如何增加字體大小?

這是BackTableVC.swift代碼:

import Foundation 

class BackTableVC: UITableViewController { 

    var tableArray = [String]() 

    override func viewDidLoad() { 
     tableArray = ["event log", "my details", "research", "share", "checklists", "templates", "helpful links", "feedback"] 
    } 

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return tableArray.count; 
    } 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: tableArray[indexPath.row], for: indexPath) as UITableViewCell 
     cell.textLabel?.text = tableArray[indexPath.row] 
     cell.textLabel?.textColor = UIColor.white 

     return cell 
    } 

如何增加字體大小?有任何想法嗎?

+0

http://stackoverflow.com/questions/7957215/how-can-i-change-the-font-size-of-my-uitableview-cell-title –

+0

您可以直接使用此cell.textLabel.font = UIFont(name:「Avenir-Book」,size:15.0) – Aditya

+0

將'cell.textLabel?.font = [UIFont systemFontOfSize:16.0];'添加到'tableView'函數中。您可以將16.0更改爲任何其他您喜歡的字體大小。 – SimpleBeat

回答

0
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: tableArray[indexPath.row], for: indexPath) as UITableViewCell 
    cell.textLabel?.font = UIFont.systemFont(ofSize: 20) 
    cell.textLabel?.text = tableArray[indexPath.row] 
    cell.textLabel?.textColor = UIColor.white 

    return cell 
} 

在上面的示例中,如果您要更改系列,則可以更改字體大小,但不更改字體系列,您可以使用此代碼。

UIFont(name: "Avenir-Book", size: 16) 
0
import UIKit 

class BackTableVC: UITableViewController{ 
    var tableArray = [String]() 
    override func viewDidLoad() { 
     tableArray = ["event log","my details","research","share","checklists","templates","helpful links","feedback"] 
    } 
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return tableArray.count; 
    } 
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: tableArray[indexPath.row], for: indexPath) as UITableViewCell 
     cell.textLabel?.text = tableArray[indexPath.row] 
     cell.textLabel?.textColor = UIColor.white 
     cell.textLabel?.font = UIFont.systemFont(ofSize: 25)//set your font size replace the 25 with your font size 

     return cell 
    } 
+0

謝謝!此代碼適用於我。 –

+0

@PremPrakashBashyal請使用綠色正確的勾號來表示可信的答案,這有助於其他....並且請回答答案 –