NewControlPackage.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. //
  2. // NewControlPackage.m
  3. // XPH
  4. //
  5. // Created by 罗云飞 on 16/7/7.
  6. // Copyright © 2016年 YAY. All rights reserved.
  7. //
  8. #import "NewControlPackage.h"
  9. @implementation NewControlPackage
  10. #pragma mark - UIButton按钮
  11. +(UIButton *)buttonInitWithTitle:(NSString *)title Frame:(CGRect)frame backgroundImage:(UIImage *)backgroundImage backgroundImageHighlighted:(UIImage *)backgroundImageHighlighted backgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor textAlignment:(UIControlContentHorizontalAlignment)textAlignment font:(UIFont *)font tag:(int)tag target:(id)target action:(SEL)action hidden:(BOOL)hidden userInteractionEnabled:(BOOL)userInteractionEnabled
  12. {
  13. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  14. [btn setFrame:frame];
  15. [btn setUserInteractionEnabled:userInteractionEnabled];
  16. [btn setTag:tag];
  17. [btn setTitle:title forState:UIControlStateNormal];
  18. [btn.titleLabel setFont:font];
  19. [btn setTitleColor:textColor forState:UIControlStateNormal];
  20. [btn setContentHorizontalAlignment:textAlignment];
  21. [btn setBackgroundColor:backgroundColor];
  22. [btn setBackgroundImage:backgroundImage forState:UIControlStateNormal];
  23. [btn setBackgroundImage:backgroundImageHighlighted forState:UIControlStateHighlighted];
  24. [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  25. [btn setHidden:hidden];
  26. return btn;
  27. }
  28. #pragma mark - UILabel标签
  29. +(UILabel *)labelInitWithFrame:(CGRect)frame text:(NSString *)text numberOfLines:(int)numberOfLines backgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment font:(UIFont *)font tag:(int)tag hidden:(BOOL)hidden adjustsFontSizeToFitWidth:(BOOL)adjustsFontSizeToFitWidth userInteractionEnabled:(BOOL)userInteractionEnabled
  30. {
  31. UILabel *label = [[UILabel alloc]initWithFrame:frame];
  32. [label setNumberOfLines:numberOfLines];
  33. [label setBackgroundColor:backgroundColor];
  34. [label setText:text];
  35. [label setTextColor:textColor];
  36. [label setTextAlignment:textAlignment];
  37. [label setFont:font];
  38. [label setTag:tag];
  39. [label setHidden:hidden];
  40. [label setAdjustsFontSizeToFitWidth:adjustsFontSizeToFitWidth];
  41. [label setUserInteractionEnabled:userInteractionEnabled];
  42. return label;
  43. }
  44. #pragma mark - UIScrollView
  45. +(UIScrollView *)scrollViewInitWithFrame:(CGRect)frame scrollEnabled:(BOOL)scrollEnabled contentSize:(CGSize)contentSize backgroundColor:(UIColor *)backgroundColor showsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator showsVerticalScrollIndicator:(BOOL)showsVerticalScrollIndicator pagingEnabled:(BOOL)pagingEnabled tag:(int)tag hidden:(BOOL)hidden userInteractionEnabled:(BOOL)userInteractionEnabled
  46. {
  47. UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:frame];
  48. [scrollView setScrollEnabled:scrollEnabled];
  49. [scrollView setContentSize:contentSize];
  50. [scrollView setBackgroundColor:backgroundColor];
  51. [scrollView setShowsHorizontalScrollIndicator:showsHorizontalScrollIndicator];
  52. [scrollView setShowsVerticalScrollIndicator:showsVerticalScrollIndicator];
  53. [scrollView setPagingEnabled:pagingEnabled];
  54. [scrollView setTag:tag];
  55. [scrollView setHidden:hidden];
  56. [scrollView setUserInteractionEnabled:userInteractionEnabled];
  57. return scrollView;
  58. }
  59. #pragma mark - UIImageView
  60. +(UIImageView *)imageViewInitWithFrame:(CGRect)frame image:(UIImage *)image highlightedImage:(UIImage *)highlightedImage backgroundColor:(UIColor *)backgroundColor tag:(int)tag hidden:(BOOL)hidden userInteractionEnabled:(BOOL)userInteractionEnabled
  61. {
  62. UIImageView *imageView = [[UIImageView alloc]initWithFrame:frame];
  63. [imageView setImage:image];
  64. [imageView setHighlightedImage:highlightedImage];
  65. [imageView setBackgroundColor:backgroundColor];
  66. [imageView setTag:tag];
  67. [imageView setHidden:hidden];
  68. [imageView setUserInteractionEnabled:userInteractionEnabled];
  69. return imageView;
  70. }
  71. #pragma mark - UITextField
  72. +(UITextField *)textFieldInitWithFrame:(CGRect)frame backgroundImage:(UIImage *)backgroundImage backgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor placeholder:(NSString *)placeholder hidden:(BOOL)hidden tag:(int)tag font:(UIFont *)font textAlignment:(NSTextAlignment)textAlignment clearButtonMode:(UITextFieldViewMode)clearButtonMode clearsOnBeginEditing:(BOOL)clearsOnBeginEditing adjustsFontSizeToFitWidth:(BOOL)adjustsFontSizeToFitWidth secureTextEntry:(BOOL)secureTextEntry keyboardType:(UIKeyboardType)keyboardType returnKeyType:(UIReturnKeyType)returnKeyType userInteractionEnabled:(BOOL)userInteractionEnabled
  73. {
  74. UITextField *textField = [[UITextField alloc]initWithFrame:frame];
  75. [textField setBackground:backgroundImage];
  76. [textField setBackgroundColor:backgroundColor];
  77. [textField setTextColor:textColor];
  78. [textField setPlaceholder:placeholder];
  79. [textField setHidden:hidden];
  80. [textField setTag:tag];
  81. [textField setFont:font];
  82. [textField setTextAlignment:textAlignment];
  83. [textField setClearButtonMode:clearButtonMode];
  84. [textField setClearsOnBeginEditing:clearsOnBeginEditing];
  85. [textField setAdjustsFontSizeToFitWidth:adjustsFontSizeToFitWidth];
  86. [textField setSecureTextEntry:secureTextEntry];
  87. [textField setKeyboardType:keyboardType];
  88. [textField setReturnKeyType:returnKeyType];
  89. [textField setUserInteractionEnabled:userInteractionEnabled];
  90. return textField;
  91. }
  92. #pragma mark - UISearchBar
  93. +(UISearchBar *)searchBarInitWithFrame:(CGRect)frame barStyle:(UIBarStyle)barStyle delegate:(id)delegate backgroundImage:(UIImage *)backgroundImage backgroundColor:(UIColor *)backgroundColor tintColor:(UIColor *)tintColor placeholder:(NSString *)placeholder hidden:(BOOL)hidden tag:(int)tag showsCancelButton:(BOOL)showsCancelButton keyboardType:(UIKeyboardType)keyboardType returnKeyType:(UIReturnKeyType)returnKeyType userInteractionEnabled:(BOOL)userInteractionEnabled
  94. {
  95. UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:frame];
  96. [searchBar setBarStyle:barStyle];
  97. [searchBar setDelegate:delegate];
  98. [searchBar setBackgroundImage:backgroundImage];
  99. [searchBar setBackgroundColor:backgroundColor];
  100. [searchBar setTintColor:tintColor];
  101. [searchBar setPlaceholder:placeholder];
  102. [searchBar setHidden:hidden];
  103. [searchBar setTag:tag];
  104. [searchBar setShowsCancelButton:showsCancelButton];
  105. [searchBar setKeyboardType:keyboardType];
  106. [searchBar setReturnKeyType:returnKeyType];
  107. [searchBar setUserInteractionEnabled:userInteractionEnabled];
  108. return searchBar;
  109. }
  110. #pragma mark - 自定义 输入框底图1
  111. +(UIImageView *)inputBoxInitWithFrame:(CGRect)frame lconImage:(UIImage *)lconImage backgroundImage:(UIImage *)backgroundImage backgroundColor:(UIColor *)backgroundColor hidden:(BOOL)hidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  112. {
  113. UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
  114. [imageView setUserInteractionEnabled:YES];
  115. [imageView setImage:backgroundImage];
  116. UIImageView *lcon = [[UIImageView alloc]initWithFrame:CGRectMake(12, (frame.size.height-20)/2, 14, frame.size.height-(frame.size.height-20))];
  117. [lcon setImage:lconImage];
  118. [imageView addSubview:lcon];
  119. return imageView;
  120. }
  121. #pragma mark - 自定义 输入框底图2
  122. +(UIView *)customView1InitWithFrame:(CGRect)frame text:(NSString *)text textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment font:(UIFont *)font backgroundColor:(UIColor *)backgroundColor hidden:(BOOL)hidden lineHidden:(BOOL)lineHidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  123. {
  124. UIView *view = [[UIView alloc]initWithFrame:frame];
  125. [view setBackgroundColor:backgroundColor];
  126. [view setHidden:hidden];
  127. [view setTag:tag];
  128. [view setUserInteractionEnabled:userInteractionEnabled];
  129. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 65, frame.size.height)];
  130. [label setBackgroundColor:backgroundColor];
  131. [label setText:text];
  132. [label setTextColor:textColor];
  133. [label setTextAlignment:textAlignment];
  134. [label setFont:font];
  135. [view addSubview:label];
  136. UIImageView *lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, frame.size.height-.6, frame.size.width-15, .6)];
  137. [lineImageView setBackgroundColor:NewCellLineColor];
  138. [lineImageView setHidden:lineHidden];
  139. [view addSubview:lineImageView];
  140. return view;
  141. }
  142. #pragma mark - 自定义 协议规则框
  143. +(UIView *)protocolRuleBarInitWithFrame:(CGRect)frame title:(NSString *)title textColor:(UIColor *)textColor textAlignment:(UIControlContentHorizontalAlignment)textAlignment font:(CGFloat)font backgroundColor:(UIColor *)backgroundColor backgroundImage:(UIImage *)backgroundImage backgroundImageSelected:(UIImage *)backgroundImageSelected target:(id)target action:(SEL)action hidden:(BOOL)hidden agreeBTTag:(int)agreeBTTag agreementBTTag:(int)agreementBTTag userInteractionEnabled:(BOOL)userInteractionEnabled
  144. {
  145. UIView *view = [[UIView alloc]initWithFrame:frame];
  146. [view setBackgroundColor:backgroundColor];
  147. [view setHidden:hidden];
  148. [view setUserInteractionEnabled:userInteractionEnabled];
  149. UIButton *agreeBT = [UIButton buttonWithType:UIButtonTypeCustom];
  150. agreeBT.frame = CGRectMake(fitScreenWidth(60), (frame.size.height-16)/2+5, 16, 16);
  151. [agreeBT setImage:backgroundImageSelected forState:UIControlStateNormal];
  152. [agreeBT setImage:backgroundImage forState:UIControlStateSelected];
  153. [agreeBT addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  154. [agreeBT setTag:agreeBTTag];
  155. [view addSubview:agreeBT];
  156. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",title] andHeight:20 fontSize:font];
  157. UIButton *agreement = [UIButton buttonWithType:UIButtonTypeCustom];
  158. agreement.frame = CGRectMake(fitScreenWidth(83), (frame.size.height-20)/2, width+10, 30);
  159. [agreement setTitle:title forState:UIControlStateNormal];
  160. [agreement setTitleColor:[UIColor colorWithString:@"#2987DE"] forState:UIControlStateNormal];
  161. [agreement.titleLabel setFont:[UIFont systemFontOfSize:font]];
  162. [agreement setContentHorizontalAlignment:textAlignment];
  163. [agreement addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  164. [agreement setTag:agreementBTTag];
  165. [view addSubview:agreement];
  166. return view;
  167. }
  168. #pragma mark - UISwitch
  169. +(UISwitch *)switchInitWithFrame:(CGRect)frame isOn:(BOOL)on hidden:(BOOL)hidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  170. {
  171. UISwitch *isSwitch = [[UISwitch alloc]initWithFrame:frame];
  172. [isSwitch setOn:on];
  173. [isSwitch setHidden:hidden];
  174. [isSwitch setTag:tag];
  175. [isSwitch setUserInteractionEnabled:userInteractionEnabled];
  176. //[isSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
  177. return isSwitch;
  178. }
  179. #pragma mark - UIView
  180. +(UIView *)viewInitWithFrame:(CGRect)frame backgroundColor:(UIColor *)backgroundColor hidden:(BOOL)hidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  181. {
  182. UIView *view = [[UIView alloc]initWithFrame:frame];
  183. [view setBackgroundColor:backgroundColor];
  184. [view setHidden:hidden];
  185. [view setTag:tag];
  186. [view setUserInteractionEnabled:userInteractionEnabled];
  187. return view;
  188. }
  189. #pragma mark - UITextView
  190. +(UITextView *)textViewInitWithFrame:(CGRect)frame scrollEnabled:(BOOL)scrollEnabled backgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor text:(NSString *)text font:(UIFont *)font textAlignment:(NSTextAlignment)textAlignment autoresizingMask:(UIViewAutoresizing)autoresizingMask keyboardType:(UIKeyboardType)keyboardType returnKeyType:(UIReturnKeyType)returnKeyType hidden:(BOOL)hidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  191. {
  192. UITextView *textView = [[UITextView alloc]initWithFrame:frame];
  193. [textView setScrollEnabled:scrollEnabled];
  194. [textView setBackgroundColor:backgroundColor];
  195. [textView setTextColor:textColor];
  196. [textView setText:text];
  197. [textView setTextAlignment:textAlignment];
  198. [textView setFont:font];
  199. [textView setAutoresizingMask:autoresizingMask];//自适应高度
  200. [textView setKeyboardType:keyboardType];
  201. [textView setReturnKeyType:returnKeyType];
  202. [textView setHidden:hidden];
  203. [textView setTag:tag];
  204. [textView setUserInteractionEnabled:userInteractionEnabled];
  205. return textView;
  206. }
  207. #pragma mark - UITableView
  208. +(UITableView *)tableViewInitWithFrame:(CGRect)frame backgroundColor:(UIColor *)backgroundColor style:(NSInteger)style delegate:(id)delegate dataSource:(id)dataSource showsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator showsVerticalScrollIndicator:(BOOL)showsVerticalScrollIndicator hidden:(BOOL)hidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  209. {
  210. UITableView *tableView = [[UITableView alloc]initWithFrame:frame style:style];
  211. [tableView setDelegate:delegate];
  212. [tableView setDataSource:dataSource];
  213. [tableView setBackgroundColor:backgroundColor];
  214. [tableView setHidden:hidden];
  215. [tableView setTag:tag];
  216. [tableView setUserInteractionEnabled:userInteractionEnabled];
  217. [tableView setShowsHorizontalScrollIndicator:showsHorizontalScrollIndicator];
  218. [tableView setShowsVerticalScrollIndicator:showsVerticalScrollIndicator];
  219. if (@available(iOS 11.0, *)) {
  220. [tableView setEstimatedRowHeight:0];
  221. [tableView setEstimatedSectionHeaderHeight:0];
  222. [tableView setEstimatedSectionFooterHeight:0];
  223. tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  224. }
  225. return tableView;
  226. }
  227. #pragma mark - UICollectionView
  228. +(UICollectionView *)collectionViewInitWithFrame:(CGRect)frame delegate:(id)delegate dataSource:(id)dataSource backgroundColor:(UIColor *)backgroundColor scrollEnabled:(BOOL)scrollEnabled alwaysBounceVertical:(BOOL)alwaysBounceVertical alwaysBounceHorizontal:(BOOL)alwaysBounceHorizontal showsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator showsVerticalScrollIndicator:(BOOL)showsVerticalScrollIndicator collectionViewFlowLayout:(UICollectionViewFlowLayout *)collectionViewFlowLayout sectionInset:(UIEdgeInsets)sectionInset headerReference:(CGSize)headerReference footerReference:(CGSize)footerReference minimumInteritemSpacing:(CGFloat)minimumInteritemSpacing minimumLineSpacing:(CGFloat)minimumLineSpacing scrollDirection:(NSInteger)scrollDirection hidden:(BOOL)hidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  229. {
  230. UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
  231. //距离边界的上下左右间距
  232. [flowLayout setSectionInset:sectionInset];
  233. //头视图CGSize
  234. [flowLayout setHeaderReferenceSize:headerReference];
  235. //尾视图CGSize
  236. [flowLayout setFooterReferenceSize:footerReference];
  237. //竖向最大间距
  238. [flowLayout setMinimumInteritemSpacing:minimumInteritemSpacing];
  239. //横向最小间距
  240. [flowLayout setMinimumLineSpacing:minimumLineSpacing];
  241. //纵/横 排序
  242. [flowLayout setScrollDirection:scrollDirection==0?UICollectionViewScrollDirectionVertical:UICollectionViewScrollDirectionHorizontal];
  243. UICollectionView *newCollectionView = [[UICollectionView alloc]initWithFrame:frame collectionViewLayout:flowLayout];
  244. //RGBACOLOR(232, 232, 227, 1)
  245. [newCollectionView setBackgroundColor:backgroundColor];
  246. [newCollectionView setDelegate:delegate];
  247. [newCollectionView setDataSource:dataSource];
  248. [newCollectionView setScrollEnabled:scrollEnabled];
  249. //是否可以纵向滑动
  250. [newCollectionView setAlwaysBounceVertical:alwaysBounceVertical];
  251. //是否可以横向滑动
  252. [newCollectionView setAlwaysBounceHorizontal:alwaysBounceHorizontal];
  253. //是否展示横向浮动条
  254. [newCollectionView setShowsHorizontalScrollIndicator:showsHorizontalScrollIndicator];
  255. //是否展示竖向浮动条
  256. [newCollectionView setShowsVerticalScrollIndicator:showsVerticalScrollIndicator];
  257. [newCollectionView setHidden:hidden];
  258. [newCollectionView setTag:tag];
  259. [newCollectionView setUserInteractionEnabled:userInteractionEnabled];
  260. //注册Cell模板
  261. //[newCollectionView registerClass:[registerClass class] forCellWithReuseIdentifier:@"Cell"];
  262. //注册头视图模板
  263. // [newCollectionView registerClass:[headerView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
  264. //注册尾视图模板
  265. // [newCollectionView registerClass:[footerView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView"];
  266. return newCollectionView;
  267. }
  268. #pragma mark - UISlider
  269. +(UISlider *)sliderInitWithFrame:(CGRect)frame minimumValue:(float)minimumValue maximumValue:(float)maximumValue value:(float)value thumbImage:(UIImage *)thumbImage minimumTrackImage:(UIImage *)minimumTrackImage maximumTrackImage:(UIImage *)maximumTrackImage minimumTrackImageResizableImageWithCapInsets:(UIEdgeInsets)minimumTrackImageResizableImageWithCapInsets resizingMode1:(NSInteger)resizingMode1 maximumTrackImageResizableImageWithCapInsets:(UIEdgeInsets)maximumTrackImageResizableImageWithCapInsets resizingMode2:(NSInteger)resizingMode2 target:(id)target action:(SEL)action hidden:(BOOL)hidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  270. {
  271. UISlider *slider = [[UISlider alloc]initWithFrame:frame];
  272. [slider setMinimumValue:minimumValue]; //最小值
  273. [slider setMaximumValue:maximumValue]; //最大值
  274. [slider setValue:value]; //默认值
  275. [slider setThumbImage:thumbImage forState:UIControlStateNormal];//滑动按钮
  276. minimumTrackImage = [minimumTrackImage resizableImageWithCapInsets:minimumTrackImageResizableImageWithCapInsets resizingMode:resizingMode1];
  277. [slider setMinimumTrackImage:minimumTrackImage forState:UIControlStateNormal];//滑动图层
  278. maximumTrackImage = [maximumTrackImage resizableImageWithCapInsets:maximumTrackImageResizableImageWithCapInsets resizingMode:resizingMode2];
  279. [slider setMaximumTrackImage:maximumTrackImage forState:UIControlStateNormal];//滑动底层
  280. [slider setHidden:hidden];
  281. [slider setTag:tag];
  282. [slider setUserInteractionEnabled:userInteractionEnabled];
  283. [slider addTarget:target action:action forControlEvents:UIControlEventValueChanged];
  284. return slider;
  285. }
  286. //UIProgressView
  287. #pragma mark - UIProgressView
  288. +(UIProgressView *)progressViewInitWithFrame:(CGRect)frame progressViewStyle:(NSInteger)progressViewStyle progress:(float)progress progressTintColor:(UIColor *)progressTintColor trackTintColor:(UIColor *)trackTintColor trackImage:(UIImage *)trackImage progressImage:(UIImage *)progressImage animated:(BOOL)animated tag:(int)tag hidden:(BOOL)hidden userInteractionEnabled:(BOOL)userInteractionEnabled
  289. {
  290. UIProgressView *progressView = [[UIProgressView alloc]init];
  291. //风格 感觉两种都差不多
  292. [progressView setProgressViewStyle:progressViewStyle];
  293. //设置的高度对进度条的高度没影响,整个高度=进度条的高度,进度条也是个圆角矩形
  294. [progressView setFrame:frame];
  295. //设置进度条上进度的颜色 默认是蓝色的
  296. [progressView setProgressTintColor:progressTintColor];
  297. //表示进度条未完成的,剩余的轨迹颜色,默认是灰色
  298. [progressView setTrackTintColor:trackTintColor];
  299. //设置进度条的背景图片
  300. [progressView setTrackImage:trackImage];
  301. //设置进度条上进度的背景图片
  302. [progressView setProgressImage:progressImage];
  303. //设置进度值并是否动画显示,这个相当于百分比,范围在0~1之间,不可以设置最大最小值
  304. [progressView setProgress:0.7 animated:animated];
  305. return progressView;
  306. }
  307. #pragma mark - 多颜色多字体的Label
  308. +(UILabel *)labelAttributedStringInitWithFrame:(CGRect)frame text1:(NSString *)text1 text2:(NSString *)text2 text3:(NSString *)text3 numberOfLines:(int)numberOfLines textAlignment:(NSTextAlignment)textAlignment textColor1:(UIColor *)textColor1 textColor2:(UIColor *)textColor2 textColor3:(UIColor *)textColor3 font:(UIFont *)font backgroundColor:(UIColor *)backgroundColor tag:(int)tag hidden:(BOOL)hidden userInteractionEnabled:(BOOL)userInteractionEnabled
  309. {
  310. NSString *str = [NSString stringWithFormat:@"%@%@%@",text1,text2,text3];
  311. NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@%@",text1,text2,text3]];
  312. NSRange range1=[[string string]rangeOfString:text1];
  313. [string addAttribute:NSForegroundColorAttributeName value:textColor1 range:range1];
  314. NSRange range2=[[string string]rangeOfString:text2];
  315. [string addAttribute:NSForegroundColorAttributeName value:textColor2 range:range2];
  316. NSRange range3=[[string string]rangeOfString:text3];
  317. [string addAttribute:NSForegroundColorAttributeName value:textColor3 range:range3];
  318. NSRange range4=[[string string]rangeOfString:str];
  319. [string addAttribute:NSFontAttributeName value:font range:range4];
  320. UILabel *label = [[UILabel alloc]initWithFrame:frame];
  321. [label setNumberOfLines:numberOfLines];
  322. [label setBackgroundColor:backgroundColor];
  323. [label setTextAlignment:textAlignment];
  324. [label setAttributedText:string];
  325. [label setTag:tag];
  326. [label setHidden:hidden];
  327. [label setUserInteractionEnabled:userInteractionEnabled];
  328. return label;
  329. }
  330. #pragma mark - JPushView 应用程序在前台时收到的推送消息展示UI
  331. +(UIView *)pushViewInitWithFrame:(CGRect)frame channel:(NSString *)channel pushText:(NSString *)pushText image:(UIImage *)image backgroundColor:(UIColor *)backgroundColor hidden:(BOOL)hidden tag:(int)tag userInteractionEnabled:(BOOL)userInteractionEnabled
  332. {
  333. UIView *view = [[UIView alloc]initWithFrame:frame];
  334. [view setBackgroundColor:backgroundColor];
  335. [view setHidden:hidden];
  336. [view setTag:tag];
  337. [view setUserInteractionEnabled:userInteractionEnabled];
  338. // [view setAlpha:.7];
  339. UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
  340. [imageView setFrame:CGRectMake(15, 10, 20, 20)];
  341. ViewRadius(imageView, 4);
  342. [view addSubview:imageView];
  343. UILabel *channelLabel = [[UILabel alloc]initWithFrame:CGRectMake(43, 8, 80, 20)];
  344. [channelLabel setBackgroundColor:[UIColor clearColor]];
  345. [channelLabel setText:channel];
  346. [channelLabel setTextColor:[UIColor whiteColor]];
  347. [channelLabel setTextAlignment:NSTextAlignmentLeft];
  348. [channelLabel setFont:[UIFont boldSystemFontOfSize:14]];
  349. [channelLabel setUserInteractionEnabled:YES];
  350. [view addSubview:channelLabel];
  351. UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(123, 8, 30, 20)];
  352. [timeLabel setBackgroundColor:[UIColor clearColor]];
  353. [timeLabel setText:@"现在"];
  354. [timeLabel setTextColor:[UIColor whiteColor]];
  355. [timeLabel setTextAlignment:NSTextAlignmentLeft];
  356. [timeLabel setFont:[UIFont systemFontOfSize:12]];
  357. [timeLabel setUserInteractionEnabled:YES];
  358. [timeLabel setAlpha:.4];
  359. [view addSubview:timeLabel];
  360. UILabel *pushTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(43, 26, SCREEN_WIDTH-60, 35)];
  361. [pushTextLabel setBackgroundColor:[UIColor clearColor]];
  362. [pushTextLabel setText:pushText];
  363. [pushTextLabel setTextColor:[UIColor whiteColor]];
  364. [pushTextLabel setTextAlignment:NSTextAlignmentLeft];
  365. [pushTextLabel setFont:[UIFont systemFontOfSize:13]];
  366. [pushTextLabel setNumberOfLines:2];
  367. [pushTextLabel setUserInteractionEnabled:YES];
  368. [view addSubview:pushTextLabel];
  369. return view;
  370. }
  371. @end