Skip to content

Instantly share code, notes, and snippets.

@lucaspang
lucaspang / UIButton+VerticalLayout.m
Created January 8, 2016 02:18
iOS UIButton center Image and Text Vertically
@interface UIButton (VerticalLayout)
- (void)centerVerticallyWithPadding:(float)padding;
- (void)centerVertically;
@end
@implementation UIButton (VerticalLayout)
- (void)centerVerticallyWithPadding:(float)padding
@lucaspang
lucaspang / gist:b94454aa164d871baa0f
Created January 8, 2016 02:16
iOS UINavigationBar hide/show hairline
@interface UINavigationBar (Addition)
- (void)hideBottomHairline;
- (void)showBottomHairline;
@end
@implementation UINavigationBar (Addition)
/**
@lucaspang
lucaspang / gist:a3e906bb28d460c1412e
Last active March 18, 2016 08:24
iOS UITableViewCell Height Calculation(iOS7-9)
//For iOS9, there is a new way(buggy in iOS7,8) to calculating the cell height
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
/* Return an estimated height or calculate
* estimated height dynamically on information
* that makes sense in your case.
@lucaspang
lucaspang / BaseTableViewCell.m
Created January 8, 2016 02:00
iOS Base UITableViewCell, prevent autolayout issue
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.baseView = [[UIView alloc] init];
[self.baseView setBackgroundColor:[UIColor whiteColor]];
[self.contentView addSubview:self.baseView];
PREPCONSTRAINTS(self.baseView);
ALIGN_TOP(self.baseView, 0);
@lucaspang
lucaspang / styles.xml
Created January 8, 2016 01:55
Android Divider Style
<!-- Divider -->
<!-- Usage: <View style="@style/Divider"/> -->
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">0.5dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
<style name="TallDivider">
<item name="android:layout_width">match_parent</item>