Skip to content

Instantly share code, notes, and snippets.

View fauc3t's full-sized avatar

Nicholas Horn fauc3t

View GitHub Profile
@fauc3t
fauc3t / UIViewExtensions.cs
Last active August 23, 2018 11:41
UIViewExtensions-members
// UI View extension methods
public static class UIViewExtensions
{
// Add these two static readonly variables
private static readonly string COLOR_BORDERS_EXT = "color-borders-ext";
private static readonly BorderDirection[] ALL_BORDERS = new BorderDirection[] { BorderDirection.Bottom, BorderDirection.Left, BorderDirection.Right, BorderDirection.Top };
...
}
@fauc3t
fauc3t / UIViewExtensions.cs
Last active August 23, 2018 11:42
color-borders-loop
// Method for coloring UIView borders
public static void ColorBorders(this UIView view, CGColor color, nfloat width, BorderDirection directions)
{
// Loop through the four possible borders
foreach(var border in ALL_BORDERS)
{
// Checks that the current border should be colored
if((border & direction) == border)
{
//TODO
@fauc3t
fauc3t / UIViewExtensions.cs
Created August 23, 2018 11:40
ui-view-extensions-initial
using CoreGraphics;
using System;
using UIKit;
namespace TextFieldValidation_Medium
{
// UI View extension methods
public static class UIViewExtensions
{
// Method for coloring UIView borders
@fauc3t
fauc3t / UIViewExtensions.cs
Created August 23, 2018 11:43
color-borders-sublayer-2
// Checks that the current border should be colored
if((border & directions) == border)
{
// Sublayer name
var name = $"{COLOR_BORDERS_EXT}.{border.ToString()}";
// Attempt to find sublayer by name
var sublayer = view.Layer.Sublayers?.FirstOrDefault(layer => layer.Name != null &&
layer.Name.Equals(name));
@fauc3t
fauc3t / UIViewExtensions.cs
Created August 23, 2018 11:45
color-borders-getframe
}
} // End foreach loop on ALL_BORDERS
// Gets the border frame based on the direction provided
CGRect GetBorderFrame(BorderDirection border)
{
switch(border)
{
case BorderDirection.Top:
return new CGRect(0, 0, view.Frame.Width, width);
@fauc3t
fauc3t / UIViewExtensions.cs
Last active August 23, 2018 11:47
color-borders-finish
...
sublayer.Frame = GetBorderFrame(border); // Border Frame
sublayer.Name = name; // Name the sublayer
sublayer.BorderWidth = width; // Set the border width
sublayer.BorderColor = color; // Set the border color
}
} // End foreach loop on ALL_BORDERS
@fauc3t
fauc3t / ViewController.cs
Created August 23, 2018 11:49
color-borders-test
public override void ViewDidLoad()
{
base.ViewDidLayoutSubviews();
NameTextField.ColorBorders(NameTextField.TextColor.CGColor, 4, BorderDirection.Bottom);
}
@fauc3t
fauc3t / BorderedTextField.cs
Created August 23, 2018 11:50
border-text-field
using CoreGraphics;
using System;
using UIKit;
namespace TextFieldValidation_Medium
{
public class BorderedTextField
{
public UITextField TextField { get; set; }
public CGColor BorderColor { get; set; }
@fauc3t
fauc3t / ViewController.cs
Created August 23, 2018 11:52
test-replace-1
NameTextField.ColorBorders(NameTextField.TextColor.CGColor, 4, BorderDirection.Bottom);
@fauc3t
fauc3t / ViewController.cs
Created August 23, 2018 11:53
test-replace-2
var borderedField = new BorderedTextField(NameTextField, NameTextField.TextColor.CGColor, BorderDirection.Bottom, 4);