Last active
December 11, 2015 22:18
-
-
Save jamonholmgren/4668372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def banner_view | |
@banner_view ||= begin | |
width = self.view.bounds.size.width | |
image = User.current_user.profile_image_view(67, 35) | |
image.frame = CGRectMake((width/2) - (67/2), 12, 67, 67) | |
BannerView.alloc.init(frame: self.view.frame, title: User.current_user.fullName, remote_image: image) | |
end | |
end |
def init(args={})
args ||= {}
if args[:frame]
width = args[:frame].size.width
else
width = App.bounds.size.width
end
top = args[:top]
top ||= 0
self.initWithFrame(CGRectMake(0, top, width, 120))
args[:banner_image] ||= "assets/pattern"
args[:mask] ||= "assets/pic-mask2"
args[:title] ||= ""
args[:icon] ||= "assets/ico-about" unless args[:remote_image]
banner_view = set_attributes UIView.alloc.initWithFrame(CGRectMake(0, 2, width, 44)), {
backgroundColor: ImageHelper.backgroundPatternFromResource(args[:banner_image])
}
banner_view.autoresizingMask = UIViewAutoresizingFlexibleWidth
pic_mask_view = ImageHelper.imageViewFromResource(args[:mask], {top: 10, center_x: (width/2)})
pic_mask_view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin
if args[:icon]
icon_view = ImageHelper.imageViewFromResource(args[:icon], {top:12, center_x: (width/2), radius: 35})
elsif args[:remote_image]
icon_view = args[:remote_image]
end
icon_view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin if icon_view
title_view = set_attributes UILabel.alloc.initWithFrame(CGRectMake(0, 90, width, 30)), {
backgroundColor: UIColor.clearColor,
text: args[:title],
font: UIFont.boldSystemFontOfSize(18),
textAlignment: UITextAlignmentCenter
}
title_view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth
self.addSubview banner_view
self.addSubview icon_view if icon_view
self.addSubview pic_mask_view
self.addSubview title_view
self.autoresizingMask = UIViewAutoresizingFlexibleWidth
self
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the image and image.frame part are too "caller-specific" to bake it into the BannerView, though.