Set padding for UITextField with UITextBorderStyleNone

I found a neat little hack to set the left padding for this exact situation. Basically, you set the leftView property of the UITextField to be an empty view of the size of the padding you want: UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)]; textField.leftView = paddingView; textField.leftViewMode = UITextFieldViewModeAlways; Worked like a … Read more

How can I pad a String in Java?

Since Java 1.5, String.format() can be used to left/right pad a given string. public static String padRight(String s, int n) { return String.format(“%-” + n + “s”, s); } public static String padLeft(String s, int n) { return String.format(“%” + n + “s”, s); } … public static void main(String args[]) throws Exception { System.out.println(padRight(“Howto”, … Read more

Structure padding and packing

Padding aligns structure members to “natural” address boundaries – say, int members would have offsets, which are mod(4) == 0 on 32-bit platform. Padding is on by default. It inserts the following “gaps” into your first structure: struct mystruct_A { char a; char gap_0[3]; /* inserted by compiler: for alignment of b */ int b; … Read more

When to use margin vs padding in CSS [closed]

TL;DR: By default I use margin everywhere, except when I have a border or background and want to increase the space inside that visible box. To me, the biggest difference between padding and margin is that vertical margins auto-collapse, and padding doesn’t. Consider two elements one above the other each with padding of 1em. This … Read more