我有标题和内容两个字符串,
在这里,我需要以20号字体和粗体显示标题,并以15号字体常规显示内容,但是我正在以相同的字体大小获得整个文本。
这是代码:
import UIKit
class RefundandCancellationViewController: UIViewController {
@IBOutlet weak var refundTextview: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
var heading = "Bills or Taxes once paid through the payment gateway shall not be refunded other then in the following circumstances:"
var content = "\n \n 1. Multiple times debiting of Consumer Card/Bank Account due to ticnical error excluding Payment Gateway charges would be refunded to the consumer with in 1 week after submitting complaint form. \n \n 2. Consumers account being debited with excess amount in single transaction due to tecnical error will be deducted in next month transaction. \n \n 3. Due to technical error, payment being charged on the consumers Card/Bank Account but the Bill is unsuccessful.
refundTextview.textColor = UIColor.gray
refundTextview.text = heading + content
}
}
您可以使用attributedText做到这一点。
这样尝试
var heading = "Bills or Taxes once paid through the payment gateway shall not be refunded other then in the following circumstances:"
var content = "\n \n 1. Multiple times debiting of Consumer Card/Bank Account due to ticnical error excluding Payment Gateway charges would be refunded to the consumer with in 1 week after submitting complaint form. \n \n 2. Consumers account being debited with excess amount in single transaction due to tecnical error will be deducted in next month transaction. \n \n 3. Due to technical error, payment being charged on the consumers Card/Bank Account but the Bill is unsuccessful."
let attributedText = NSMutableAttributedString(string: heading, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 20)])
attributedText.append(NSAttributedString(string: content, attributes: [NSAttributedStringKey.font: UIFont.SystemFont(ofSize: 15), NSAttributedStringKey.foregroundColor: UIColor.blue]))
refundTextview.attributedText = attributedText
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句