📄 mycustomcell.m
字号:
//// File: MyCustomCell.m//// Abstract: Custom table view cell to present custom information.//// Version: 1.7//// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple")// in consideration of your agreement to the following terms, and your use,// installation, modification or redistribution of this Apple software// constitutes acceptance of these terms. If you do not agree with these// terms, please do not use, install, modify or redistribute this Apple// software.//// In consideration of your agreement to abide by the following terms, and// subject to these terms, Apple grants you a personal, non - exclusive// license, under Apple's copyrights in this original Apple software ( the// "Apple Software" ), to use, reproduce, modify and redistribute the Apple// Software, with or without modifications, in source and / or binary forms;// provided that if you redistribute the Apple Software in its entirety and// without modifications, you must retain this notice and the following text// and disclaimers in all such redistributions of the Apple Software. Neither// the name, trademarks, service marks or logos of Apple Inc. may be used to// endorse or promote products derived from the Apple Software without specific// prior written permission from Apple. Except as expressly stated in this// notice, no other rights or licenses, express or implied, are granted by// Apple herein, including but not limited to any patent rights that may be// infringed by your derivative works or by other works in which the Apple// Software may be incorporated.//// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION// ALONE OR IN COMBINATION WITH YOUR PRODUCTS.//// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.//// Copyright (C) 2008 Apple Inc. All Rights Reserved.//#import "MyCustomCell.h"#import "Constants.h"@implementation MyCustomCell@synthesize dataDictionary;@synthesize nameLabel;@synthesize explainLabel;#define LEFT_COLUMN_OFFSET 10#define LEFT_COLUMN_WIDTH 220 #define UPPER_ROW_TOP 0#define CELL_HEIGHT 50 - (id)initWithFrame:(CGRect)aRect reuseIdentifier:(NSString *)identifier{ self = [super initWithFrame:aRect reuseIdentifier:identifier]; if (self) { // you can do this here specifically or at the table level for all cells self.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // Create label views to contain the various pieces of text that make up the cell. // Add these as subviews. nameLabel = [[UILabel alloc] initWithFrame:CGRectZero]; // layoutSubViews will decide the final frame nameLabel.backgroundColor = [UIColor clearColor]; nameLabel.opaque = NO; nameLabel.textColor = [UIColor blackColor]; nameLabel.highlightedTextColor = [UIColor whiteColor]; nameLabel.font = [UIFont boldSystemFontOfSize:18]; [self.contentView addSubview:nameLabel]; explainLabel = [[UILabel alloc] initWithFrame:CGRectZero]; // layoutSubViews will decide the final frame explainLabel.backgroundColor = [UIColor clearColor]; explainLabel.opaque = NO; explainLabel.textColor = [UIColor grayColor]; explainLabel.highlightedTextColor = [UIColor whiteColor]; explainLabel.font = [UIFont systemFontOfSize:14]; [self.contentView addSubview:explainLabel]; } return self;}- (void)layoutSubviews{ [super layoutSubviews]; CGRect contentRect = [self.contentView bounds]; // In this example we will never be editing, but this illustrates the appropriate pattern CGRect frame = CGRectMake(contentRect.origin.x + LEFT_COLUMN_OFFSET, UPPER_ROW_TOP, LEFT_COLUMN_WIDTH, CELL_HEIGHT); nameLabel.frame = frame; frame = CGRectMake(contentRect.origin.x + 65.0 + LEFT_COLUMN_OFFSET, UPPER_ROW_TOP, LEFT_COLUMN_WIDTH, CELL_HEIGHT); explainLabel.frame = frame;}- (void)dealloc{ [nameLabel release]; [explainLabel release]; [dataDictionary release]; [super dealloc];}- (void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:animated]; // when the selected state changes, set the highlighted state of the lables accordingly nameLabel.highlighted = selected;}- (void)setDataDictionary:(NSDictionary *)newDictionary{ if (dataDictionary == newDictionary) { return; } [dataDictionary release]; dataDictionary = [newDictionary retain]; // update value in subviews nameLabel.text = [dataDictionary objectForKey:kTitleKey]; explainLabel.text = [dataDictionary objectForKey:kExplainKey];}@end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -