1

Hello I am new to xamarin. I'm coding in c# for iOS native and I need a simple outset border on an GRect element created from the UIKIT. I thought it could be as simple as ...

     textTile.BorderStyle = UITextBorderStyle.Bezel; 

That of coarse isn't working. I just need to add a bezel or outset border. It could be a border from any particular style or view system... How do I implement it?

full code of the section:

    private void makeTiles(){
    UILabel textTile = new UILabel();
    CGRect tileFrame = new CGRect(0, 0, 100, 100);

    textTile.Frame = tileFrame;

    textTile.BackgroundColor = UIColor.Grey;
    textTile.BorderStyle = UITextBorderStyle.Bezel; 
    textTile.Text = "1";


    textTile.TextAlignment = UITextAlignment.Center;

    textTile.Font = UIFont.SystemFontOfSize(25); }
  • Have a look at this https://www.appcoda.com/bezier-paths-introduction/ , you can have a try with override control's draw() method. – Junior Jiang Aug 05 '19 at 06:03

1 Answers1

0

Welcome to Xamarin!

Scenario 1: All sided border

So I am going to assume you want to add a border all around the label. In order to do that, you can just use the border properties of the Layer class in the textTile that comes from it being a UILabel.

textTile.Layer.BorderColor = UIColor.Red.CGColor;
textTile.Layer.BorderWidth = 0.75;

Scenario 2: 1 sided border

If you want to add a bezel, I assume you want to only add color to the bottom, so in that case it is recommended to place the label inside another view. So the master UIView would have two subviews-UILabel for your text, and a UIView for your bezel. The UIView subview would be

  • Color - Light gray
  • The same height as your bottom border that you wanted
  • The same width as your label

2 scenarios explained

Saamer
  • 4,687
  • 1
  • 13
  • 55
  • That's great. I added a picture to explain the second scenario. Let me know if it makes sense now :) – Saamer Aug 03 '19 at 22:54
  • The picture was just an image I put together. You could use the Xcode Interface Builder for it too. Share the rest of your class code, and I ll try to place it into your work – Saamer Aug 04 '19 at 05:20
  • the code https://github.com/SunRhythms/iosslidingpuzzle/tree/master/iOSSlidingPuzzle-3 – amaze interactive Aug 04 '19 at 22:48
  • I am also trying to get this in ooui can you help... question here... https://stackoverflow.com/questions/57349529/how-to-deploy-your-xamarin-ios-to-the-web-as-a-progressive-web-application-pwa – amaze interactive Aug 04 '19 at 22:49
  • I get a 404 error while going to the github link, it seems to be private. Also, for ooui unfortunately, you can't port Xamarin.iOS code to Web/Desktop for now. You could do so if you used Xamarin.Forms, but still not very reliably. Xamarin is not good for PWA, but its great for Native coding as it also allows using Native libraries through "bindings". – Saamer Aug 06 '19 at 15:20