框架:
 
所有代码文件
 
Model:
  1. //
  2. // Message.h
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8. // message信息模型,存储聊天记录
  9.  
  10. #import <Foundation/Foundation.h>
  11.  
  12. typedef enum {
  13. MessageTypeMe = , // 我发出的信息
  14. MessageTypeOhter = // 对方发出的信息
  15. } MessageType;
  16.  
  17. @interface Message : NSObject
  18.  
  19. /** 信息 */
  20. @property(nonatomic, copy) NSString *text;
  21.  
  22. /** 发送时间 */
  23. @property(nonatomic, copy) NSString *time;
  24.  
  25. /** 发送方 */
  26. @property(nonatomic, assign) MessageType type;
  27.  
  28. /** 是否隐藏发送时间 */
  29. @property(nonatomic, assign) BOOL hideTime;
  30.  
  31. - (instancetype) initWithDictionary:(NSDictionary *) dictionary;
  32. + (instancetype) messageWithDictionary:(NSDictionary *) dictionary;
  33. + (instancetype) message;
  34.  
  35. @end
 
  1. //
  2. // Message.m
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8.  
  9. #import "Message.h"
  10.  
  11. @implementation Message
  12.  
  13. - (instancetype) initWithDictionary:(NSDictionary *) dictionary {
  14. if (self = [super init]) {
  15. [self setValuesForKeysWithDictionary:dictionary];
  16. }
  17.  
  18. return self;
  19. }
  20.  
  21. + (instancetype) messageWithDictionary:(NSDictionary *) dictionary {
  22. return [[self alloc] initWithDictionary:dictionary];
  23. }
  24.  
  25. + (instancetype) message {
  26. return [self messageWithDictionary:nil];
  27. }
  28.  
  29. @end
 
  1. //
  2. // MessageFrame.h
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8. // 存储每个cell内子控件的位置尺寸的frame
  9.  
  10. #import <Foundation/Foundation.h>
  11. #import <UIKit/UIKit.h>
  12. #import "Message.h"
  13.  
  14. #define MESSAGE_TIME_FONT [UIFont systemFontOfSize:13]
  15. #define MESSAGE_TEXT_FONT [UIFont systemFontOfSize:15]
  16. #define TEXT_INSET 20
  17.  
  18. @interface MessageFrame : NSObject
  19.  
  20. /** 发送时间 */
  21. @property(nonatomic, assign, readonly) CGRect timeFrame;
  22.  
  23. /** 头像 */
  24. @property(nonatomic, assign, readonly) CGRect iconFrame;
  25.  
  26. /** 信息 */
  27. @property(nonatomic, assign, readonly) CGRect textFrame;
  28.  
  29. /** 信息model */
  30. @property(nonatomic, strong) Message *message;
  31.  
  32. /** cell的高度 */
  33. @property(nonatomic, assign) CGFloat cellHeight;
  34.  
  35. @end
 
  1. //
  2. // MessageFrame.m
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8.  
  9. #import "MessageFrame.h"
  10. #import "NSString+Extension.h"
  11.  
  12. @implementation MessageFrame
  13.  
  14. /** 设置message,计算位置尺寸 */
  15. - (void)setMessage:(Message *)message {
  16. _message = message;
  17.  
  18. // 间隙
  19. CGFloat padding = ;
  20.  
  21. // 1.发送时间
  22. if (NO == message.hideTime) {
  23. CGFloat timeWidth = [UIScreen mainScreen].bounds.size.width;
  24. CGFloat timeHeight = ;
  25. CGFloat timeX = ;
  26. CGFloat timeY = ;
  27. _timeFrame = CGRectMake(timeX, timeY, timeWidth, timeHeight);
  28. }
  29.  
  30. // 2.头像
  31. CGFloat iconWidth = ;
  32. CGFloat iconHeight = ;
  33.  
  34. // 2.1 根据信息的发送方调整头像位置
  35. CGFloat iconX;
  36. if (MessageTypeMe == message.type) {
  37. // 我方,放在右边
  38. iconX = [UIScreen mainScreen].bounds.size.width - padding - iconWidth;
  39. } else {
  40. // 对方,放在左边
  41. iconX = padding;
  42. }
  43.  
  44. CGFloat iconY = CGRectGetMaxY(_timeFrame) + padding;
  45. _iconFrame = CGRectMake(iconX, iconY, iconWidth, iconHeight);
  46.  
  47. // 3.信息,尺寸可变
  48. CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
  49. // 3.1 设置文本最大尺寸
  50. CGSize textMaxSize = CGSizeMake(screenWidth - iconWidth - padding * , MAXFLOAT);
  51. // 3.2 计算文本真实尺寸
  52. CGSize textRealSize = [message.text sizeWithFont:MESSAGE_TEXT_FONT maxSize:textMaxSize];
  53.  
  54. // 3.3 按钮尺寸
  55. CGSize btnSize = CGSizeMake(textRealSize.width + TEXT_INSET*, textRealSize.height + TEXT_INSET*);
  56.  
  57. // 3.4 调整信息的位置
  58. CGFloat textX;
  59. if (MessageTypeMe == message.type) {
  60. // 我方,放在靠右
  61. textX = CGRectGetMinX(_iconFrame) - btnSize.width - padding;
  62. } else {
  63. // 对方,放在靠左
  64. textX = CGRectGetMaxX(_iconFrame) + padding;
  65. }
  66.  
  67. CGFloat textY = iconY;
  68. _textFrame = CGRectMake(textX, textY, btnSize.width, btnSize.height);
  69.  
  70. // 4.cell的高度
  71. CGFloat iconMaxY = CGRectGetMaxY(_iconFrame);
  72. CGFloat textMaxY = CGRectGetMaxY(_textFrame);
  73. _cellHeight = MAX(iconMaxY, textMaxY) + padding;
  74. }
  75.  
  76. @end
 
View:
  1. //
  2. // MessageCell.h
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10.  
  11. #define BACKGROUD_COLOR [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1.0]
  12.  
  13. @class MessageFrame, Message;
  14.  
  15. @interface MessageCell : UITableViewCell
  16.  
  17. /** 持有存储了聊天记录和聊天框位置尺寸的frame */
  18. @property(nonatomic, strong) MessageFrame *messageFrame;
  19.  
  20. /** 传入父控件tableView引用的构造方法 */
  21. + (instancetype) cellWithTableView:(UITableView *) tableView;
  22.  
  23. @end
 
  1. //
  2. // MessageCell.m
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8.  
  9. #import "MessageCell.h"
  10. #import "MessageFrame.h"
  11. #import "UIImage+Extension.h"
  12.  
  13. @interface MessageCell()
  14.  
  15. // 定义cell内的子控件,用于保存控件,然后进行数据和位置尺寸的计算
  16. /** 发送时间 */
  17. @property(nonatomic, weak) UILabel *timeLabel;
  18.  
  19. /** 头像 */
  20. @property(nonatomic, weak) UIImageView *iconView;
  21.  
  22. /** 信息 */
  23. @property(nonatomic, weak) UIButton *textView;
  24.  
  25. @end
  26.  
  27. @implementation MessageCell
  28.  
  29. - (void)awakeFromNib {
  30. // Initialization code
  31. }
  32.  
  33. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  34. [super setSelected:selected animated:animated];
  35.  
  36. // Configure the view for the selected state
  37. }
  38.  
  39. #pragma mark - 构造方法
  40. // 自定义构造方法
  41. + (instancetype) cellWithTableView:(UITableView *) tableView {
  42. static NSString *ID = @"message";
  43.  
  44. // 使用缓存池
  45. MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  46.  
  47. // 创建一个新的cell
  48. if (nil == cell) {
  49. cell = [[MessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
  50. }
  51.  
  52. return cell;
  53. }
  54.  
  55. // 重写构造方法,创建cell中的各个子控件
  56. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  57. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  58.  
  59. // 设置cell的背景色
  60. self.backgroundColor = BACKGROUD_COLOR;
  61.  
  62. // 1.发送时间
  63. UILabel *timeLabel = [[UILabel alloc] init];
  64. [timeLabel setTextAlignment:NSTextAlignmentCenter];
  65. [timeLabel setFont:MESSAGE_TIME_FONT];
  66. [timeLabel setTextColor:[UIColor grayColor]];
  67. [self.contentView addSubview:timeLabel];
  68. self.timeLabel = timeLabel;
  69.  
  70. // 2.头像
  71. UIImageView *iconView = [[UIImageView alloc] init];
  72. [self.contentView addSubview:iconView];
  73. self.iconView = iconView;
  74.  
  75. // 3.信息
  76. UIButton *textView = [[UIButton alloc] init];
  77. [textView setTitle:@"text" forState:UIControlStateNormal];
  78. [textView.titleLabel setFont:MESSAGE_TEXT_FONT];
  79.  
  80. // 3.1 如果是浅色背景,记得设置字体颜色,因为按钮的字体颜色默认是白色
  81. [textView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  82. [textView.titleLabel setNumberOfLines:]; // 设置自动换行
  83.  
  84. // 3.2 调整文字的内边距
  85. textView.contentEdgeInsets = UIEdgeInsetsMake(TEXT_INSET, TEXT_INSET, TEXT_INSET, TEXT_INSET);
  86.  
  87. [self.contentView addSubview:textView];
  88. self.textView = textView;
  89.  
  90. return self;
  91. }
  92.  
  93. #pragma mark - 加载数据
  94. // 加载frame,初始化cell中子控件的数据、位置尺寸
  95. - (void)setMessageFrame:(MessageFrame *) messageFrame {
  96. _messageFrame = messageFrame;
  97.  
  98. // 1.发送时间
  99. self.timeLabel.text = messageFrame.message.time;
  100. self.timeLabel.frame = messageFrame.timeFrame;
  101.  
  102. // 2.头像
  103. NSString *icon = (messageFrame.message.type == MessageTypeMe)? @"me":@"other";
  104. self.iconView.image = [UIImage imageNamed:icon];
  105. self.iconView.frame = messageFrame.iconFrame;
  106.  
  107. // 3.信息
  108. [self.textView setTitle:messageFrame.message.text forState:UIControlStateNormal];
  109. self.textView.frame = messageFrame.textFrame;
  110.  
  111. // 3.1 设置聊天框
  112. NSString *chatImageNormalName;
  113. NSString *chatImageHighlightedName;
  114. if (MessageTypeMe == messageFrame.message.type) {
  115. chatImageNormalName = @"chat_send_nor";
  116. chatImageHighlightedName = @"chat_send_press_pic";
  117. } else {
  118. chatImageNormalName = @"chat_receive_nor";
  119. chatImageHighlightedName = @"chat_receive_press_pic";
  120. }
  121.  
  122. UIImage *chatImageNormal = [UIImage resizableImage:chatImageNormalName];
  123. UIImage *chatImageHighlighted = [UIImage resizableImage:chatImageHighlightedName];
  124. [self.textView setBackgroundImage:chatImageNormal forState:UIControlStateNormal];
  125. [self.textView setBackgroundImage:chatImageHighlighted forState:UIControlStateHighlighted];
  126. }
  127.  
  128. @end
 
Controller:
  1. //
  2. // ViewController.m
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. #import "Message.h"
  11. #import "MessageCell.h"
  12. #import "MessageFrame.h"
  13.  
  14. @interface ViewController () <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>
  15.  
  16. /** 聊天区tableView */
  17. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  18.  
  19. /** 信息记录数据 */
  20. @property(nonatomic, strong) NSMutableArray *messages;
  21.  
  22. /** 信息输入框 */
  23. @property (weak, nonatomic) IBOutlet UITextField *inputView;
  24.  
  25. @end
  26.  
  27. @implementation ViewController
  28.  
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. // Do any additional setup after loading the view, typically from a nib.
  32.  
  33. // 设置dataSource
  34. self.tableView.dataSource = self;
  35.  
  36. // 设置tableView的delegate
  37. self.tableView.delegate = self;
  38.  
  39. // 设置tableView背景色,当键盘呼出隐藏的时候,避免默认的黑色背景出现太突兀
  40. self.tableView.backgroundColor = BACKGROUD_COLOR;
  41.  
  42. // 设置聊天区TableView
  43. // 不使用分割线
  44. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  45. // 禁止选中cell
  46. [self.tableView setAllowsSelection:NO];
  47.  
  48. // 设置虚拟键盘监听器
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
  50.  
  51. // 设置TextField文字左间距
  52. self.inputView.leftView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  53. self.inputView.leftViewMode = UITextFieldViewModeAlways;
  54.  
  55. // 设置信息输入框的代理
  56. self.inputView.delegate = self;
  57. }
  58.  
  59. - (void)didReceiveMemoryWarning {
  60. [super didReceiveMemoryWarning];
  61. // Dispose of any resources that can be recreated.
  62. }
  63.  
  64. - (BOOL)prefersStatusBarHidden {
  65. return YES;
  66. }
  67.  
  68. #pragma mark - 数据加载
  69. /** 延迟加载plist文件数据 */
  70. - (NSMutableArray *)messages {
  71. if (nil == _messages) {
  72. NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"messages.plist" ofType:nil]];
  73.  
  74. NSMutableArray *mdictArray = [NSMutableArray array];
  75. for (NSDictionary *dict in dictArray) {
  76. Message *message = [Message messageWithDictionary:dict];
  77.  
  78. // 判断是否发送时间与上一条信息的发送时间相同,若是则不用显示了
  79. MessageFrame *lastMessageFrame = [mdictArray lastObject];
  80. if (lastMessageFrame && [message.time isEqualToString:lastMessageFrame.message.time]) {
  81. message.hideTime = YES;
  82. }
  83.  
  84. MessageFrame *messageFrame = [[MessageFrame alloc] init];
  85. messageFrame.message = message;
  86. [mdictArray addObject:messageFrame];
  87. }
  88.  
  89. _messages = mdictArray;
  90. }
  91.  
  92. return _messages;
  93. }
  94.  
  95. #pragma mark - dataSource方法
  96. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  97. return self.messages.count;
  98. }
  99.  
  100. - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  101. MessageCell *cell = [MessageCell cellWithTableView:self.tableView];
  102. cell.messageFrame = self.messages[indexPath.row];
  103.  
  104. return cell;
  105. }
  106.  
  107. #pragma mark - tableView代理方法
  108. /** 动态设置每个cell的高度 */
  109. - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  110. MessageFrame *messageFrame = self.messages[indexPath.row];
  111. return messageFrame.cellHeight;
  112. }
  113.  
  114. #pragma mark - scrollView 代理方法
  115. /** 点击拖曳聊天区的时候,缩回键盘 */
  116. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  117. // 1.缩回键盘
  118. [self.view endEditing:YES];
  119. }
  120.  
  121. #pragma mark - 监听事件
  122. - (void) keyboardWillChangeFrame:(NSNotification *) note {
  123. // 1.取得弹出后的键盘frame
  124. CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  125.  
  126. // 2.键盘弹出的耗时时间
  127. CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
  128.  
  129. // 3.键盘变化时,view的位移,包括了上移/恢复下移
  130. CGFloat transformY = keyboardFrame.origin.y - self.view.frame.size.height;
  131.  
  132. [UIView animateWithDuration:duration animations:^{
  133. self.view.transform = CGAffineTransformMakeTranslation(, transformY);
  134. }];
  135. }
  136.  
  137. #pragma mark - TextField 代理方法
  138. /** 回车响应事件 */
  139. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  140. // 我方发出信息
  141. [self sendMessageWithContent:textField.text andType:MessageTypeMe];
  142.  
  143. // 自动回复
  144. [self sendMessageWithContent:[NSString stringWithFormat:@"%@\n%@", textField.text, @"你妹!!!"] andType:MessageTypeOhter];
  145.  
  146. // 消除消息框内容
  147. self.inputView.text = nil;
  148.  
  149. [self.tableView reloadData];
  150.  
  151. // 滚动到最新的消息
  152. NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:self.messages.count - inSection:];
  153. [self.tableView scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  154.  
  155. return YES; // 返回值意义不明
  156. }
  157.  
  158. // 发送消息
  159. - (void) sendMessageWithContent:(NSString *) text andType:(MessageType) type {
  160. // 获取当前时间
  161. NSDate *date = [NSDate date];
  162. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  163. formatter.dateFormat = @"yyyy-MMM-dd hh:mm:ss";
  164. NSString *dateStr = [formatter stringFromDate:date];
  165.  
  166. // 我方发出信息
  167. NSDictionary *dict = @{@"text":text,
  168. @"time":dateStr,
  169. @"type":[NSString stringWithFormat:@"%d", type]};
  170.  
  171. Message *message = [[Message alloc] init];
  172. [message setValuesForKeysWithDictionary:dict];
  173. MessageFrame *messageFrame = [[MessageFrame alloc] init];
  174. messageFrame.message = message;
  175.  
  176. [self.messages addObject:messageFrame];
  177. }
  178.  
  179. @end
工具类:
  1. //
  2. // NSString+Extension.h
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8. // NSString扩展类
  9.  
  10. #import <Foundation/Foundation.h>
  11. #import <UIKit/UIKit.h>
  12.  
  13. @interface NSString (Extension)
  14.  
  15. /** 测量文本的尺寸 */
  16. - (CGSize) sizeWithFont:(UIFont *)font maxSize:(CGSize) maxSize;
  17.  
  18. @end
 
  1. //
  2. // NSString+Extension.m
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8.  
  9. #import "NSString+Extension.h"
  10.  
  11. @implementation NSString (Extension)
  12.  
  13. /** 测量文本的尺寸 */
  14. - (CGSize)sizeWithFont:(UIFont *)font maxSize:(CGSize)maxSize {
  15. NSDictionary *attrs = @{NSFontAttributeName: font};
  16. CGSize size = [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
  17.  
  18. return size;
  19. }
  20.  
  21. @end
 
  1. //
  2. // UIImage+Extension.h
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8. // NSImage 类的扩展
  9.  
  10. #import <Foundation/Foundation.h>
  11. #import <UIKit/UIKit.h>
  12.  
  13. @interface UIImage (Extension)
  14.  
  15. + (UIImage *) resizableImage:(NSString *) imageName;
  16.  
  17. @end
  1. //
  2. // UIImage+Extension.m
  3. // QQChatDemo
  4. //
  5. // Created by hellovoidworld on 14/12/8.
  6. // Copyright (c) 2014年 hellovoidworld. All rights reserved.
  7. //
  8.  
  9. #import "UIImage+Extension.h"
  10.  
  11. @implementation UIImage (Extension)
  12.  
  13. + (UIImage *) resizableImage:(NSString *) imageName {
  14. UIImage *image = [UIImage imageNamed:imageName];
  15. // 取图片中部的1 x 1进行拉伸
  16. UIEdgeInsets insets = UIEdgeInsetsMake(image.size.height/, image.size.width/, image.size.height/ + , image.size.width/ + );
  17. return [image resizableImageWithCapInsets:insets];
  18. }
  19.  
  20. @end
 
 

[iOS基础控件 - 6.9.1] 聊天界面Demo 代码的更多相关文章

  1. [iOS基础控件 - 6.11.3] 私人通讯录Demo 控制器的数据传递、存储

    A.需求 1.搭建一个"私人通讯录"Demo 2.模拟登陆界面 账号 密码 记住密码开关 自动登陆开关 登陆按钮 3.退出注销 4.增删改查 5.恢复数据(取消修改)   这个代码 ...

  2. [iOS基础控件 - 3.1] QQ登陆界面

      A.storyboard 控件版 1.label 2.textfield      a.Keyboard Type           账号:Number Pad           密码:Num ...

  3. [iOS基础控件 - 5.5] 代理设计模式 (基于”APP列表"练习)

    A.概述      在"[iOS基础控件 - 4.4] APP列表 进一步封装,初见MVC模式”上进一步改进,给“下载”按钮加上效果.功能      1.按钮点击后,显示为“已下载”,并且不 ...

  4. [iOS基础控件 - 6.9] 聊天界面Demo

    A.需求 做出一个类似于QQ.微信的聊天界面 1.每个cell包含发送时间.发送人(头像).发送信息 2.使用对方头像放在左边,我方头像在右边 3.对方信息使用白色背景对话框,我方信息使用蓝色背景对话 ...

  5. iOS 基础控件(下)

    上篇介绍了UIButton.UILabel.UIImageView和UITextField,这篇就简短一点介绍UIScrollView和UIAlertView. UIScrollView 顾名思义也知 ...

  6. [iOS基础控件 - 7.0] UIWebView

    A.基本使用 1.概念 iOS内置的浏览器控件 Safari浏览器就是通过UIWebView实现的   2.用途:制作简易浏览器 (1)基本请求 创建请求 加载请求 (2)代理监听webView加载, ...

  7. [iOS基础控件 - 6.10.2] PickerView 自定义row内容 国家选择Demo

    A.需求 1.自定义一个UIView和xib,包含国家名和国旗显示 2.学习row的重用   B.实现步骤 1.准备plist文件和国旗图片     2.创建模型 // // Flag.h // Co ...

  8. iOS基础 - 控件属性

    一.控件的属性 1.CGRect frame 1> 表示控件的位置和尺寸(以父控件的左上角为坐标原点(0, 0)) 2> 修改这个属性,可以调整控件的位置和尺寸 2.CGPoint cen ...

  9. [iOS基础控件 - 6.12.3] @property属性 strong weak copy

    A.概念 @property 的修饰词   strong: 强指针/强引用(iOS6及之前是retain) weak: 弱智真/弱引用(iOS6及之前是assign)   默认情况所有指针都是强指针 ...

随机推荐

  1. Java开发之反射的使用

    通过类名获取类. Class serviceManager = Class.forName("android.os.ServiceManager"); 获取方法 Method me ...

  2. 【笨嘴拙舌WINDOWS】伟大的变革

    "改革"."革命"."变革" 这几个词语毫无疑问是每一个时代必须被呼吁的词语,当一个国家没有人求变时,那是一个时代的悲剧.无论是文景之治,贞 ...

  3. Qt之运行一个实例进程

    简述 发布程序的时候,我们往往会遇到这种情况: 只需要用户运行一个实例进程 用户可以同时运行多个实例进程 一个实例进程的软件有很多,例如:360.酷狗- 多个实例进程的软件也很多,例如:Visual ...

  4. AssetManager asset的使用

    Android 系统为每个新设计的程序提供了/assets目录,这个目录保存的文件可以打包在程序里./res 和/assets的不同点是,android不为/assets下的文件生成ID.如果使用/a ...

  5. System.web.optimization 在 Asp.Net WebForm 中应用得注意了

    我们也可以在Asp.Net WebForm项目中去使用Optimization,去处理我们的资源文件,从而起到优化网站性能的效果,前端知识得从小事做起.但是在使用过程中我却发现了下面的问题. 第一步: ...

  6. RESTful API 设计最佳实践(转)

    背景 目前互联网上充斥着大量的关于RESTful API(为方便,下文中“RESTful API ”简写为“API”)如何设计的文章,然而却没有一个”万能“的设计标准:如何鉴权?API 格式如何?你的 ...

  7. shell -Z- d等等代表

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 [ -a FILE ]   ...

  8. Android手动画柱状图的例子

    效果图如上,网上看到的例子,谨以此文记录一下,以后用到的地方再来翻翻. 核心技术是用Canvas和Paint画长方形. 源码地址:http://download.csdn.net/detail/abc ...

  9. hdu 2059(dp)

    题意:容易理解... 思路:dp[i]表示乌龟到达第i个充电站时最少花费时间到第 i 个充电站后,从起点开始遍历到第 i-1 个充电站,得到最少花费时间 状态转移方程:dp[i]=min(dp[j]+ ...

  10. 22、TTS技术

    Android对TTS技术的支持 Android 1.6开始支持TTS(Text To Speech)技术,通过该技术可以将文本转换成语音. TTS技术的核心是android.speech.tts.T ...