小编Ahs*_*san的帖子

Textview Center文本对齐IOS 7

-(void)observeValueForKeyPath:(NSString *)keyPath   ofObject:(id)object   change:(NSDictionary *)change   context:(void *)context 
{
    NSLog(@"Hello");
    UITextView *tv = object;
    CGFloat topCorrect = ([tv bounds].size.height - [tv contentSize].height * [tv zoomScale])  / 2.0;
    topCorrect = ( topCorrect < 0.0 ? 0.0 : topCorrect );
    tv.contentOffset = (CGPoint){.x = 0, .y = -topCorrect};
}
Run Code Online (Sandbox Code Playgroud)

我在Viewdidload中这样称呼它

[myTextView1 addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1