Adding left margin to UITextView

前端 未结 6 708
臣服心动
臣服心动 2021-02-05 17:25

I\'m trying to add a left margin to a UITextView.

I\'ve tried setting the property contentInset, see below:

UITextView *textView = [[UITextView alloc] in         


        
6条回答
  •  失恋的感觉
    2021-02-05 17:46

    The ONLY thing worked for me is by sub-classing the UITextView and overriding the following method:

        - (id)styleString
    {
        return [[super styleString] stringByAppendingString:@"; line-height: 1.6em;margin-right: 30px; margin-left: 45px; margin-top: 20px;"];
    }
    

    Apparently; you can tweak the margin-left, margin-top & whatever you want ;)


    The suggestion about placing the UITextView in a larger UIView didn't work for me as I needed to scrollable lines in the background of UITextView, I used the following open-source project to do that: https://github.com/aahsanali/NoteView

    Also, the following solution didn't help me at all:

    [textView setContentInset:UIEdgeInsetsMake(0, 20, 0,-20)]
    

    As it wasn't wrapping text correctly.

    I hope this solution helps as I literally spent a week digging into this simple UI tweak!

提交回复
热议问题