简体   繁体   中英

Add a border to a UIView not working

I am trying to add a border to a UIView inside a custom cell. I am trying:

partial class EventCell : UITableViewCell
{
    public EventCell (IntPtr handle) : base (handle)
    {

    }

    public void SetUpCell(Event eventObj)
    {
        title.Text = eventObj.title;
        cellFooter.Layer.BorderColor = new MonoTouch.CoreGraphics.CGColor (224f, 224f, 224f);
        cellFooter.Layer.BorderWidth = 5.0f;
        cellFooter.Layer.MasksToBounds = true;
    }
}

Any Ideas?

Using cellFooter.Layer.BorderColor = UIColor.FromRGB(224,224,224).CGColor; instead of creating a new CGcolor fixed it.

Add the 'clipsToBounds' property as below

cellFooter.layer.borderWidth = 5.0f;
cellFooter.layer.borderColor = [UIColor blueColor].CGColor;
cellFooter.clipsToBounds= YES;

I fix it just in function drawRect, then fill this code

cellFooter.layer.borderWidth = 5.0f;
cellFooter.layer.borderColor = [UIColor blueColor].CGColor;

You need to use view's layer to set border property. eg:

import

...

view.layer.borderColor = [UIColor redColor].CGColor;
view.layer.borderWidth = 3.0f;

You also need to link with QuartzCore.framework to access this functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM