Align text in a UIAlertView that has a scrollbar

那年仲夏 提交于 2019-12-11 12:55:47

问题


If a UIAlertView contains a certain amount of text, the text display is automatically changed to have scrollbars. I would like this text to be centre-aligned.

Searching around for the solution provides this SO response. However, this does not work on a UIAlertView that contains scrollbars.

How do I align the text in such an alert?


回答1:


My suggestion would be to not do this. It could break with any iOS update if Apple changes the way that UIAlertView is structured. That being said, you can do this:

for(id subview in alertView.subviews) {
    if([subview isKindOfClass:[UITextView class]]) {
        [(UITextView *)subview setTextAlignment:NSTextAlignmentCenter];
    }
}


来源:https://stackoverflow.com/questions/13113653/align-text-in-a-uialertview-that-has-a-scrollbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!