开发者

how to set vertical align of uitextview from interface builder

I have a problem in my application design. I want to set vertical align middle of my UITextView. Please help me how to set vertical align o开发者_JAVA技巧f uitextview from interface builder.


Got this to work by observing changes to the contentSize property and then setting 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]; 
}


*yourtextviewname*.textAlignment=UITextAlignmentCenter;

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜