Answers for "bold attributed text swift"

1

how to bold text swiftui

import SwiftUI

struct ContentView: View {
    @State var TextValue: String = "Hello"

    var body: some View {
        VStack {
            TextField("placeholder", text: $TextValue)
            .padding(.horizontal, 50)
                .font(.system(size: 30, weight: .heavy, design: .default))
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Posted by: Guest on February-02-2021
0

how to bold 1 word swift

extension String {
func withBoldText(text: String, font: UIFont? = nil) -> NSAttributedString {
  let _font = font ?? UIFont.systemFont(ofSize: 14, weight: .regular)
  let fullString = NSMutableAttributedString(string: self, attributes: [NSAttributedString.Key.font: _font])
  let boldFontAttribute: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: _font.pointSize)]
  let range = (self as NSString).range(of: text)
  fullString.addAttributes(boldFontAttribute, range: range)
  return fullString
}}


// USE CASE:
       let text = "Discover New Shops.".withBoldText(text: "New")
       label.attributedText =  headerTitle
Posted by: Guest on June-21-2020

Code answers related to "bold attributed text swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language