Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the code for following component</p> <p><img src="https://i.stack.imgur.com/FFWkZ.png" alt="enter image description here"></p> <pre><code>@interface AZTextField () - (void)privateInitialization; @end @implementation AZTextField static CGFloat const kAZTextFieldCornerRadius = 3.0; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (!self) return nil; [self privateInitialization]; return self; } // In case you decided to use it in a nib - (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (!self) return nil; [self privateInitialization]; return self; } - (void)privateInitialization { self.borderStyle = UITextBorderStyleNone; self.layer.masksToBounds = NO; self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOffset = CGSizeMake(0.0f, 5.0f); self.layer.shadowOpacity = 0.5f; self.layer.backgroundColor = [UIColor whiteColor].CGColor; self.layer.cornerRadius = 4; // This code is better to be called whenever size of the textfield changed, // so if you plan to do that you can add an observer for bounds property UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:kAZTextFieldCornerRadius]; self.layer.shadowPath = shadowPath.CGPath; } @end </code></pre> <p>Couple of things to consider:</p> <ul> <li>You want to set borderStyle to none, otherwise you'll end up with UIKit putting subviews into your textfield</li> <li>Depending on the Xcode version you might want to link QuartzCore and to <code>#import &lt;QuartzCore/QuartzCore.h&gt;</code> </li> <li>For more complex appearance you can still use shadow properties of the layer and move the drawing code itself into the <code>drawRect:</code> method, but jake_hetfield was right if you override drawRect you don't want to call super, especially in the end of the method </li> <li>As for the text drawing (you can see that it sticks to close to the component borders), you have a separate <code>drawTextInRect:</code> and <code>drawPlaceholderInRect:</code> method that draws the text and placeholder respectively </li> <li>You can use UIColor method for colors and call CGColor property, it makes code more readable and easier to maintain</li> </ul> <p>Hope that helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload