ios - Textfield placeholder font creates issue -


enter image description here

i have added button rightview textfield.

i have set attributed text custom font placeholder text.

my textfield's placeholder , text font different.

but when textfield's text large , if select whole text , remove not shows me placeholder text in font. shows in textfield's text font.

detail explanation :

  • my textfield's text font : opensans bold 18.0
  • my textfield's placeholder text font : opensans 18.0 (regular)

but when select hole text (large) , delete text shows place holder text in: opensans bold 18.0

but should shows place holder text in: opensans 18.0 (regular)

enter image description here

i think have set font every time placeholder appears/disappears. set textfield delegate , add code...

func textfield(textfield: uitextfield, shouldchangecharactersinrange range: nsrange, replacementstring string: string) -> bool {      let length = (textfield.text?.characters.count)! + (string.characters.count - range.length)      // if there text in text field     if (length > 0) {         // set textfield font         textfield.font = uifont(name: "opensans bold", size: 18)     } else {         // set textfield placeholder font (or appears)         textfield.font = uifont(name: "opensans regular", size: 18)     }      return true; } 

obj-c:

- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {         // if there text in text field     if (textfield.text.length + (string.length - range.length) > 0) {         // set textfield font         textfield.font = [uifont fontwithname:@"opensans bold" size:18];     } else {         // set textfield placeholder font (or appears)         textfield.font = [uifont fontwithname:@"opensans regular" size:18];     }      return yes; } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -