ios - Converting an NSColor to a UIColor from an NSAttributedString -
i trying check colour of specific words in attributed string. can access attribute can't convert attribute dictionary uicolor.
first enumerate on attributed string, returns, each different attributed, dictionary of attributes. can closer @ each.
nsattributedstring * attributes = self.textview.attributedtext; [attributes enumerateattributesinrange:nsmakerange(0, attributes.length) options:0 usingblock:^(nsdictionary<nsstring *,id> * _nonnull attrs, nsrange range, bool * _nonnull stop) { }];
when return attrs dictionary (with hkwmentionattributename being subclass using):
{ hkwmentionattributename = "<0x610000243450> (hkwmentionsattribute) text: abc name 1, id: uy5vv8qzbxhpob8jtxubebmtaed3, no range"; nscolor = "uiextendedsrgbcolorspace 1 0 0 1"; nsfont = "<uictfont: 0x7fd388558ce0> font-family: \".sfuitext\"; font-weight: normal; font-style: normal; font-size: 19.00pt"; }
i access color attrs[@"nscolor"];
, returned below:
uiextendedsrgbcolorspace 1 0 0 1
i can't life of me figure out how turn uicolor or begin use object.
i understand 1 0 0 1
red, green, blue , alpha don't know how access them use colorwithred
function.
this link seems suggest need change color space doesn't give more of explanation that.
this link makes me feel shouldn't trying import nscolor class osx class
i have tried usual color go-tos: attempting load cgcolor
, cicolor
, loading cgcolorgetcomponents
, loading nsstring
, loading id
see if shine more light on issue.
i feel problem understanding of uicolor
, nscolor
objects there little information can find helps convert between two.
@"nscolor"
, despite coincidentally sharing name of appkit class, raw value of nsforegroundcolorattributename
constant. on ios, documented uicolor
. therefore, should able take attrs[nsforegroundcolorattributename]
, cast uicolor
, , use it.
Comments
Post a Comment