相关疑难解决方法(0)

给UIView圆角

我的登录视图有一个子视图,其中有一个UIActivityView和一个UILabel说"登录...".此子视图的拐角不是圆角.我怎样才能让它们成圆形?

有没有办法在我的xib中做到这一点?

cocoa-touch uiview ios

562
推荐指数
11
解决办法
31万
查看次数

如何使用Swift创建一个简单的集合视图

我正在努力学习如何使用UICollectionView.该文件是一个有点难以理解,而我发现教程无论是在目标C或长期复杂的项目当中.

当我学习如何使用时UITableView,我们❤Swift的 如何用iOS 8和Swift制作一个简单的桌面视图有一个非常基本的设置和解释让我去.有这样的东西UICollectionView吗?

下面的答案是我试图学习如何做到这一点.

ios uicollectionview swift

171
推荐指数
2
解决办法
16万
查看次数

UIView底部边界?

对于UIScrollView *toScrollView(这是屏幕的宽度),我想添加一个灰色的底部边框(与iPhone的原生消息应用程序的撰写视图的to-field完全相同).

为了做到这一点,我跟随Cocoa Touch:如何改变UIView的边框颜色和厚度?并使用自定义覆盖顶部边框UINavigationBar并制作了toScrollViewx坐标-1和宽度322,以便左右边框就在屏幕外.

这看起来很好,但它有点像黑客,我想知道是否有更好的方法来做到这一点.

- (void)viewDidLoad {
    [super viewDidLoad];

    // Add UINavigationBar *navigationBar at top.
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
                                             initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                             target:self action:@selector(cancelAction)];
    UINavigationBar *navigationBar = [[UINavigationBar alloc]
                                      initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
    navigationBar.items = [NSArray arrayWithObject:self.navigationItem];

    // Add UIScrollView *toScrollView below navigationBar.
    UIScrollView *toScrollView = [[UIScrollView alloc]
                                  initWithFrame:CGRectMake(-1.0f, 43.0f, 322.0f, 45.0f)];
    toScrollView.backgroundColor = [UIColor whiteColor];
    toScrollView.layer.borderColor = [UIColor colorWithWhite:0.8f alpha:1.0f].CGColor;
    toScrollView.layer.borderWidth = 1.0f;
    [self.view addSubview:toScrollView];
    [self.view addSubview:navigationBar]; // covers top of toScrollView …
Run Code Online (Sandbox Code Playgroud)

border uiview ios

140
推荐指数
12
解决办法
13万
查看次数

如何在UILabel周围画边框?

UILabel有没有办法在自己周围划出边界?这对我调试文本位置以及查看位置和标签实际大小非常有用.

iphone cocoa-touch uikit uilabel ios

135
推荐指数
4
解决办法
11万
查看次数

在UIImageView上设置角半径不起作用

我有点失落.我已经使用UIView的图层属性来围绕我的应用程序中的多个元素的角落.但是,这一个UIImageView根本就不符合.不确定我错过了什么.

UIImageView(称为previewImage)包含在表视图单元格中.我已经尝试将cornerRadius属性设置为多个位置(在单元格本身和创建单元格的控制器中)无济于事.

static NSString *CellIdentifier = @"MyTableViewCell";

MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
    cell = [topLevelObjects objectAtIndex:0];
    cell.previewImage.layer.cornerRadius = 20; //Made it 20 to make sure it's obvious.
}
Run Code Online (Sandbox Code Playgroud)

有没有关于细胞加载的方式,我错过了?

iphone rounded-corners uiimageview ios

121
推荐指数
4
解决办法
8万
查看次数

使用swift 3在UIView上添加Shadow

之前的swift 3我在我的UIView中添加阴影,如下所示:

//toolbar is an UIToolbar (UIView)
toolbar.layer.masksToBounds = false
toolbar.layer.shadowOffset = CGSize(width: -1, height: 1)
toolbar.layer.shadowRadius = 1
toolbar.layer.shadowOpacity = 0.5
Run Code Online (Sandbox Code Playgroud)

但上面的代码不能在swift 3中工作,而不是阴影我的整个View的颜色变成了丑陋的灰色

谁知道我们如何在swift 3中添加阴影?

ios swift3

61
推荐指数
7
解决办法
11万
查看次数

UIView的clipsToBounds和CALayer的maskToBounds之间的关系如何?

A UIView有一个CALayer.这很确定.但两者似乎都提供了同样的东西.

如果我设置clipsToBounds=YES,这还会设置图层masksToBounds=YES吗?为什么不同名字?有谁知道?

core-animation calayer uikit uiview ios

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

UIView有阴影,圆角和自定义drawRect

我必须创建一个UIView具有圆角,边框,阴影的自定义,并drawRect()重写其方法以提供自定义绘图代码,在该代码中将几条直线绘制到视图中(我需要使用快速,轻量级的方法,因为许多可以呈现这些视图).

我目前面临的问题是,一旦我drawRect()在视图类中重写(即使其中没​​有任何自定义代码),阴影也不再适用于圆角.请参阅附图中的差异:

在此输入图像描述

在视图控制器中我使用以下代码:

    view.layer.cornerRadius = 10;
    view.layer.masksToBounds = true;

    view.layer.borderColor = UIColor.grayColor().CGColor;
    view.layer.borderWidth = 0.5;

    view.layer.contentsScale = UIScreen.mainScreen().scale;
    view.layer.shadowColor = UIColor.blackColor().CGColor;
    view.layer.shadowOffset = CGSizeZero;
    view.layer.shadowRadius = 5.0;
    view.layer.shadowOpacity = 0.5;
    view.layer.masksToBounds = false;
    view.clipsToBounds = false;
Run Code Online (Sandbox Code Playgroud)

在被覆盖的drawContext()我会使用类似的东西:

    var context:CGContext = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(context, UIColor.redColor().CGColor);
    // Draw them with a 2.0 stroke width so they are a bit more visible.
    CGContextSetLineWidth(context, 2.0);
    CGContextMoveToPoint(context, 0.0, 0.0); //start at this point
    CGContextAddLineToPoint(context, 20.0, 20.0); //draw to …
Run Code Online (Sandbox Code Playgroud)

objective-c uiview drawrect ios swift

50
推荐指数
5
解决办法
9万
查看次数

UITableViewCell:圆角和阴影

我正在改变UITableViewCell的宽度,以便单元格更小,但用户仍然可以沿着tableview的边缘滚动.

override func layoutSubviews() {        
    // Set the width of the cell
    self.bounds = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width - 40, self.bounds.size.height)
    super.layoutSubviews()
}
Run Code Online (Sandbox Code Playgroud)

然后我绕过角落:

cell.layer.cornerRadius = 8
cell.layer.masksToBounds = true
Run Code Online (Sandbox Code Playgroud)

到目前为止都很好.阴影会出现问题.边界被掩盖,因此阴影显然不会出现.我已经查找了其他答案,但似乎无法弄清楚如何沿着边界圆角并显示阴影.

cell.layer.shadowOffset = CGSizeMake(0, 0)
cell.layer.shadowColor = UIColor.blackColor().CGColor
cell.layer.shadowOpacity = 0.23
cell.layer.shadowRadius = 4
Run Code Online (Sandbox Code Playgroud)

所以我的问题 - 如何减小宽度,绕角,并同时为UITableViewCell添加阴影?

更新:尝试R Moyer的回答

尝试R Moyer的回答

uitableview swift

47
推荐指数
6
解决办法
6万
查看次数

我什么时候应该将layer.shouldRasterize设置为YES

我已经通过设置视图的图层属性看到了一些lagyness问题的修复

view.layer.shouldRasterize = YES;
Run Code Online (Sandbox Code Playgroud)

我在使用UICollectionView并准备单元格和设置属性时看到了很大的性能差异.

不确定其含义是什么.

得到解释会很棒.谢谢!

rasterizing uiview ios uicollectionview

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