I want to put the left margin of a UITextField
's text at 10 px. What is the best way to do that?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
As I have explained in a previous comment, the best solution in this case is to extend the
UITextField
class instead of using a category, so you can use it explicitly on the desired text fields.A category is intended to add new functions to an existing class, not to override an existing method.
i have reached almost by overriding
- (CGRect)textRectForBounds:(CGRect)bounds
. now issue is when TextField goes in to edit mode their left margin reset to Zero .......Try this code
I was hoping to see a setting in IB in the property inspector to adjust this value. Turns out I had set alignment and border style inadvertently to values that messed with the padding on the left.
You wouldn't think it would be a big deal to choose left justify and no border but it makes the words basically overlap or come right to the edge of the box and it doesn't look right.
Bad:
Good:
Fixed it right up for me. Hope this helps someone else as well.
For Swift 4:
I prefer to use
IBDesignable
class andIBInspectable
properties to allow me to set the padding via Xcode storyboards and keep it reusable. I've also updated the code to work in Swift 4.You can try this