質問

In ios7 the border on a default tableviewcell is always the same size regardless of whether you view it in a non-retina or retina device, i.e it isn't scaled up. How can I achieve the same effect when working with a CALayer to create a border? I've tried

     CALayer *borderLayer = [CALayer layer];
        [borderLayer setBorderColor:[UIColor redColor].CGColor];

        [borderLayer setBorderWidth:1];
        [borderLayer setContentsScale:1.0f];

but the border seems to double in size for retina still. Does anyone know how I can get around this?

Sorry I've realised something I've missed out here. As in the tableView example I only want the border to be on one side e.g just the top. If I use setBorder it obviously draws a border on all sides of a frame. If I set the frame of my layer to 0.5 it doesn't show at all and if I set it to 1 it obviously appears thicker again.

Because of the aforementioned 0.5f height issue for the frame I can't use setBackgroundColor and a frame of 0.5f either as it fails to render.

Is my only option to go down more basic drawing methods?

Based on the answer by sage444 I used the background color rather than a border and the following

        if([UIScreen mainScreen].scale > 1.0f){
     [topBorder setFrame:CGRectMake(0,0,width,0.5f)];
}else{
     [topBorder setFrame:CGRectMake(0,0,width,1.0f)];
}
役に立ちましたか?

解決

to draw one pixel line on CALayer you should set width to 0.5f, for non retina display it will be 1 pixel, and on retina you get also 1 retina pixel line.

To check that is retina display use contentsScale

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top