1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- /*
- Copyright (c) 2013 Katsuma Tanaka
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
- #import "QBImagePickerGroupCell.h"
- @implementation QBImagePickerGroupCell
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
-
- if(self) {
- /* Initialization */
- // Title
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
- titleLabel.font = [UIFont boldSystemFontOfSize:17];
- titleLabel.textColor = [UIColor blackColor];
- titleLabel.highlightedTextColor = [UIColor whiteColor];
- titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
-
- [self.contentView addSubview:titleLabel];
- self.titleLabel = titleLabel;
- // [titleLabel release];
-
- // Count
- UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
- countLabel.font = [UIFont systemFontOfSize:17];
- countLabel.textColor = [UIColor colorWithWhite:0.498 alpha:1.0];
- countLabel.highlightedTextColor = [UIColor whiteColor];
- countLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
-
- [self.contentView addSubview:countLabel];
- self.countLabel = countLabel;
- // [countLabel release];
- }
-
- return self;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated
- {
- [super setSelected:selected animated:animated];
-
- self.titleLabel.highlighted = selected;
- self.countLabel.highlighted = selected;
- }
- - (void)layoutSubviews
- {
- [super layoutSubviews];
-
- CGFloat height = self.contentView.bounds.size.height;
- CGFloat imageViewSize = height - 1;
- CGFloat width = self.contentView.bounds.size.width - 20;
-
- // CGSize titleTextSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font forWidth:width lineBreakMode:NSLineBreakByTruncatingTail];
- // CGSize countTextSize = [self.countLabel.text sizeWithFont:self.countLabel.font forWidth:width lineBreakMode:NSLineBreakByTruncatingTail];
-
- CGSize titleTextSize = [self.titleLabel.text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.titleLabel.font} context:nil].size;
- CGSize countTextSize = [self.countLabel.text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.countLabel.font} context:nil].size;
-
- CGRect titleLabelFrame;
- CGRect countLabelFrame;
-
- if((titleTextSize.width + countTextSize.width + 10) > width) {
- titleLabelFrame = CGRectMake(imageViewSize + 20, 0, width - countTextSize.width - 10, imageViewSize);
- countLabelFrame = CGRectMake(titleLabelFrame.origin.x + titleLabelFrame.size.width + 10, 0, countTextSize.width, imageViewSize);
- } else {
- titleLabelFrame = CGRectMake(imageViewSize + 20, 0, titleTextSize.width, imageViewSize);
- countLabelFrame = CGRectMake(titleLabelFrame.origin.x + titleLabelFrame.size.width + 10, 0, countTextSize.width, imageViewSize);
- }
-
- self.titleLabel.frame = titleLabelFrame;
- self.countLabel.frame = countLabelFrame;
- }
- - (void)dealloc
- {
- // [_titleLabel release];
- // [_countLabel release];
- //
- // [super dealloc];
- }
- @end
|