ios - Center and bold part of a text in Swift -
i want center , bold title of paragraph. far can make title bold cant center it.
here's code:
let title = "title of paragraph" let attrs = [nsfontattributename : uifont.boldsystemfontofsize(15)] let boldstring = nsmutableattributedstring(string:title, attributes:attrs) let normaltext = "something here.............." let attributedstring = nsmutableattributedstring(string:normaltext) boldstring.appendattributedstring(attributedstring) label.attributedtext = boldstring
i tried add attribue in attrs:
let attrs = [nsfontattributename : uifont.boldsystemfontofsize(15), nstextalignment: nstextalignment.center]
i'm not sure if that's correct way center it, still gives error "type of expression ambiguous without more context"
i've searched error seems still can't fix problem
i think problem nstextalignment
key trying add on dictionary. it's type int
becomes ambiguous previous key string
guess that's why compiler complaining. either way nstextalignment
not valid key used on nsmutableattributedstring
attributes initialiser.
maybe looking that:
let string = "any string" let style = nsmutableparagraphstyle() style.alignment = .center let attributes = [ nsfontattributename: uifont.boldsystemfontofsize(15), nsparagraphstyleattributename: style ] let attributedstring = nsmutableattributedstring(string: string, attributes: attributes)
Comments
Post a Comment