-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
239 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// DemoCodeAutoLayout.h | ||
// RollingNotice | ||
// | ||
// Created by zgy on 2020/4/15. | ||
// Copyright © 2020 qm. All rights reserved. | ||
// | ||
|
||
#import "GYNoticeViewCell.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface DemoCodeAutoLayout : GYNoticeViewCell | ||
|
||
|
||
|
||
@property (nonatomic, strong) UILabel *customLab; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// DemoCodeAutoLayout.m | ||
// RollingNotice | ||
// | ||
// Created by zgy on 2020/4/15. | ||
// Copyright © 2020 qm. All rights reserved. | ||
// | ||
|
||
#import "DemoCodeAutoLayout.h" | ||
|
||
@implementation DemoCodeAutoLayout | ||
|
||
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier | ||
{ | ||
self = [super initWithReuseIdentifier:reuseIdentifier]; | ||
if (self) { | ||
[self setupUI]; | ||
} | ||
return self; | ||
} | ||
|
||
// cell 高度30 | ||
- (void)setupUI | ||
{ | ||
UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; | ||
[self.contentView addSubview:testBtn]; | ||
// testBtn.frame = CGRectMake(10, 5, 20, 20); | ||
testBtn.translatesAutoresizingMaskIntoConstraints = NO; | ||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[v]" options:0 metrics:nil views:@{@"v": testBtn}]]; | ||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v]" options:0 metrics:nil views:@{@"v": testBtn}]]; | ||
|
||
[testBtn addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[v(30)]" options:0 metrics:nil views:@{@"v": testBtn}]]; | ||
[testBtn addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[v(60)]" options:0 metrics:nil views:@{@"v": testBtn}]]; | ||
|
||
|
||
|
||
_customLab = [[UILabel alloc]init]; | ||
_customLab.textColor = [UIColor redColor]; | ||
_customLab.backgroundColor = [UIColor lightGrayColor]; | ||
[self.contentView addSubview:_customLab]; | ||
|
||
_customLab.translatesAutoresizingMaskIntoConstraints = NO; | ||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[v]|" options:0 metrics:nil views:@{@"v": _customLab}]]; | ||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-80-[v]" options:0 metrics:nil views:@{@"v": _customLab}]]; | ||
[_customLab addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[v(160)]" options:0 metrics:nil views:@{@"v": _customLab}]]; | ||
|
||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// ThirdViewController.h | ||
// RollingNotice | ||
// | ||
// Created by zgy on 2020/4/15. | ||
// Copyright © 2020 qm. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface ThirdViewController : UIViewController | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// ThirdViewController.m | ||
// RollingNotice | ||
// | ||
// Created by zgy on 2020/4/15. | ||
// Copyright © 2020 qm. All rights reserved. | ||
// | ||
|
||
#import "ThirdViewController.h" | ||
#import "DemoCodeAutoLayout.h" | ||
#import "GYRollingNoticeView.h" | ||
|
||
@interface ThirdViewController ()<GYRollingNoticeViewDataSource, GYRollingNoticeViewDelegate> | ||
|
||
{ | ||
NSArray *_arr; | ||
|
||
} | ||
@property (nonatomic, strong) GYRollingNoticeView *noticeView; | ||
@end | ||
|
||
@implementation ThirdViewController | ||
|
||
- (instancetype)init | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
|
||
_arr = @[@"小米千元全面屏:抱歉,久等!625献上", | ||
// @"可怜狗狗被抛弃,苦苦等候主人半年", | ||
// @"三星中端新机改名,全面屏火力全开", | ||
// @"学会这些,这5种花不用去花店买了", | ||
// @"华为nova2S发布,剧透了荣耀10?" | ||
]; | ||
|
||
|
||
_noticeView = [[GYRollingNoticeView alloc] init]; | ||
_noticeView.delegate = self; | ||
_noticeView.dataSource = self; | ||
|
||
[self.view addSubview:_noticeView]; | ||
|
||
|
||
[_noticeView registerClass:[DemoCodeAutoLayout class] forCellReuseIdentifier:@"DemoCodeAutoLayout"]; | ||
|
||
[_noticeView reloadDataAndStartRoll]; | ||
|
||
_noticeView.translatesAutoresizingMaskIntoConstraints = NO; | ||
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-160-[v]" options:0 metrics:nil views:@{@"v": _noticeView}]]; | ||
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[v]-20-|" options:0 metrics:nil views:@{@"v": _noticeView}]]; | ||
|
||
[_noticeView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[v(30)]" options:0 metrics:nil views:@{@"v": _noticeView}]]; | ||
|
||
} | ||
return self; | ||
} | ||
|
||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
self.view.backgroundColor = [UIColor whiteColor]; | ||
} | ||
|
||
|
||
- (void)viewWillDisappear:(BOOL)animated | ||
{ | ||
[super viewWillDisappear:animated]; | ||
[_noticeView stopRoll]; | ||
} | ||
|
||
|
||
#pragma mark- <GYRollingNoticeViewDataSource, GYRollingNoticeViewDelegate> | ||
- (NSInteger)numberOfRowsForRollingNoticeView:(GYRollingNoticeView *)rollingView | ||
{ | ||
return _arr.count; | ||
} | ||
- (__kindof GYNoticeViewCell *)rollingNoticeView:(GYRollingNoticeView *)rollingView cellAtIndex:(NSUInteger)index | ||
{ | ||
DemoCodeAutoLayout *cell = [rollingView dequeueReusableCellWithIdentifier:@"DemoCodeAutoLayout"]; | ||
cell.customLab.text = _arr[index]; | ||
return cell; | ||
|
||
} | ||
|
||
- (void)didClickRollingNoticeView:(GYRollingNoticeView *)rollingView forIndex:(NSUInteger)index | ||
{ | ||
NSLog(@"点击的index: %d", rollingView.currentIndex); | ||
} | ||
|
||
@end |
Oops, something went wrong.