How to set uitextview vertical alignment from interface designer

I have a problem in the design of my application. I want to set the vertical alignment to the middle of my UITextView. Please help me set the vertical alignment of uitextview from the interface constructor.

+5
source share
2 answers

For this to work, by observing the changes to the contentSize property and then setting the contentOffset.

- (void)viewDidLoad{
    [super viewDidLoad];
    [myTextView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:nil];
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    UITextView *myView = object;

    CGFloat offSet = ([myView bounds].size.height - [myView contentSize].height * [myView zoomScale])/2.0;
    offSet = offSet < 0.0 ? 0.0 : offSet;
    [myView setContentOffset:CGPointMake(0, -offSet) animated:NO]; 
}
+7
source
*yourtextviewname*.textAlignment=UITextAlignmentCenter;

You can do this using the builder interface. Open the attributes of the text field and set the text Alignment to the center.

-1
source

All Articles