3
Page 1 of 3 UnfriendView.m 4/2/15, 8:59 PM // // AppDelegate.m // Friend-Duster // // Created by Bryan Crampton on 3/26/15. // Copyright (c) 2015 Orange Slide Apps, Inc. All rights reserved. // #import "UnfriendView.h" #import <QuartzCore/QuartzCore.h> @implementation UnfriendView static UIImage *_defaultImage; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.masksToBounds = YES; self.layer.cornerRadius = 8.0f; self.layer.borderColor = [UIColor lightGrayColor].CGColor; self.layer.borderWidth = 2.0f; self.backgroundColor = [UIColor whiteColor]; profilePicImageView = [[UIImageView alloc] init]; nameLabel = [[UILabel alloc] init]; unfriendButton = [[UIButton alloc] init]; unfollowButton = [[UIButton alloc] init]; keepButton = [[UIButton alloc] init]; [self addSubview:profilePicImageView]; [self addSubview:nameLabel]; [self addSubview:unfriendButton]; [self addSubview:unfollowButton]; [self addSubview:keepButton]; [self customizeSubviews]; } return self; } - (void)customizeSubviews { profilePicImageView.contentMode = UIViewContentModeScaleAspectFill; nameLabel.font = [UIFont defaultBoldFont]; unfriendButton.backgroundColor = [UIColor redColor]; unfollowButton.backgroundColor = [UIColor yellowColor]; keepButton.backgroundColor = [UIColor greenColor]; unfriendButton.titleLabel.font = [UIFont defaultBoldFont]; unfollowButton.titleLabel.font = [UIFont defaultBoldFont]; keepButton.titleLabel.font = [UIFont defaultBoldFont];

UnfriendView.m

Embed Size (px)

DESCRIPTION

Objective-C code for an UnfriendView

Citation preview

  • Page 1 of 3

    UnfriendView.m 4/2/15, 8:59 PM

    //// AppDelegate.m// Friend-Duster//// Created by Bryan Crampton on 3/26/15.// Copyright (c) 2015 Orange Slide Apps, Inc. All rights reserved.//

    #import "UnfriendView.h"#import

    @implementation UnfriendView

    static UIImage *_defaultImage;

    - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.masksToBounds = YES; self.layer.cornerRadius = 8.0f; self.layer.borderColor = [UIColor lightGrayColor].CGColor; self.layer.borderWidth = 2.0f; self.backgroundColor = [UIColor whiteColor];

    profilePicImageView = [[UIImageView alloc] init]; nameLabel = [[UILabel alloc] init]; unfriendButton = [[UIButton alloc] init]; unfollowButton = [[UIButton alloc] init]; keepButton = [[UIButton alloc] init]; [self addSubview:profilePicImageView]; [self addSubview:nameLabel]; [self addSubview:unfriendButton]; [self addSubview:unfollowButton]; [self addSubview:keepButton]; [self customizeSubviews]; } return self;}

    - (void)customizeSubviews { profilePicImageView.contentMode = UIViewContentModeScaleAspectFill; nameLabel.font = [UIFont defaultBoldFont]; unfriendButton.backgroundColor = [UIColor redColor]; unfollowButton.backgroundColor = [UIColor yellowColor]; keepButton.backgroundColor = [UIColor greenColor]; unfriendButton.titleLabel.font = [UIFont defaultBoldFont]; unfollowButton.titleLabel.font = [UIFont defaultBoldFont]; keepButton.titleLabel.font = [UIFont defaultBoldFont];

  • Page 2 of 3

    UnfriendView.m 4/2/15, 8:59 PM

    [unfriendButton setTitleColor:[UIColor whiteColor] forState:

    UIControlStateNormal]; [unfollowButton setTitleColor:[UIColor whiteColor] forState:

    UIControlStateNormal]; [keepButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [unfriendButton setTitleColor:[UIColor lightGrayColor] forState:

    UIControlStateSelected]; [unfollowButton setTitleColor:[UIColor lightGrayColor] forState:

    UIControlStateSelected]; [keepButton setTitleColor:[UIColor lightGrayColor] forState:

    UIControlStateSelected]; [unfriendButton setTitle:@"Unfriend" forState:UIControlStateNormal]; [unfollowButton setTitle:@"Unfollow" forState:UIControlStateNormal]; [keepButton setTitle:@"Keep" forState:UIControlStateNormal];}

    - (void)layoutSubviews { [super layoutSubviews]; float leftPadding = 0.1f*self.width; float paddedWidth = self.width - 0.2f*self.width; profilePicImageView.x = leftPadding; profilePicImageView.width = paddedWidth; profilePicImageView.y = profilePicImageView.x; profilePicImageView.height = profilePicImageView.width; float verticalSpaceLeft = self.height - (profilePicImageView.y +

    profilePicImageView.height); float paddedHeight = verticalSpaceLeft/2 - 0.2f*(verticalSpaceLeft/2); nameLabel.x = leftPadding; nameLabel.width = paddedWidth; nameLabel.y = + profilePicImageView.y + profilePicImageView.height + 0.1f*

    (verticalSpaceLeft/2); nameLabel.height = paddedHeight; float buttonsY = nameLabel.y + nameLabel.height + 0.1f*(verticalSpaceLeft); float buttonsWidth = self.width/3; unfriendButton.x = 0; unfriendButton.width = buttonsWidth; unfriendButton.y = buttonsY; unfriendButton.height = paddedHeight; unfollowButton.x = buttonsWidth; unfollowButton.width = buttonsWidth; unfollowButton.y = buttonsY; unfollowButton.height = paddedHeight;

    keepButton.x = 2*buttonsWidth; keepButton.width = buttonsWidth; keepButton.y = buttonsY; keepButton.height = paddedHeight;

  • Page 3 of 3

    UnfriendView.m 4/2/15, 8:59 PM

    }

    #pragma mark - Instance Methods- (void)setProfilePicURL:(NSURL *)profilePicURL { if (!_defaultImage) { _defaultImage = [UIImage imageNamed:@"default-photo.jpg"]; } [profilePicImageView sd_setImageWithURL:profilePicURL placeholderImage:

    _defaultImage];}

    - (void)setName:(NSString *)name { nameLabel.text = name;}

    @end