OGeek|极客世界-中国程序员成长平台

标题: ios - UIView 宽度问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 13:18
标题: ios - UIView 宽度问题

我在 UIView 中有两个高度和宽度相同的表格 View 。我正在尝试在表格 View 之间放置一个分隔线(宽度为 1px 的 UIView),如图所示,但它看起来像 2px 宽。我已经尝试将分隔线放在 .xib 中并以编程方式放置,但我遇到了同样的问题。我想实现一个厚度与 tableview 单元格分隔线粗细相同的分隔线。

UIView *vLine = [[UIView alloc]initWithFrame:CGRectMake(300,0,1,500)];
vLine.backgroundColor = [UIColor colorWithRed:207.0f/255.0f green:207.0f/255.0f blue:207.0f/255.0f alpha:1.0];
[self.view addSubview:vLine];

enter image description here



Best Answer-推荐答案


试试这个,因为它更健壮:

CGFloat screenScale = [[UIScreen mainScreen] scale];
UIView *vLine = [[UIView alloc] initWithFrame:CGRectMake(300, 0, 1 / screenScale, 500)];

关于ios - UIView 宽度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27467327/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4