Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions SDCycleScrollView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
TargetAttributes = {
9900D16D1ABEB2490077A6CB = {
CreatedOnToolsVersion = 6.1;
DevelopmentTeam = MLHLEFRACM;
ProvisioningStyle = Automatic;
};
9900D1861ABEB2490077A6CB = {
Expand Down Expand Up @@ -557,10 +558,11 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = MLHLEFRACM;
INFOPLIST_FILE = SDCycleScrollView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nuqian.nuqian;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -575,10 +577,11 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = MLHLEFRACM;
INFOPLIST_FILE = SDCycleScrollView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nuqian.nuqian;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
12 changes: 6 additions & 6 deletions SDCycleScrollView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>-.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -22,6 +22,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand All @@ -34,10 +39,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@

#import <UIKit/UIKit.h>



@interface SDCollectionViewCell : UICollectionViewCell

@property (weak, nonatomic) UIImageView *imageView;
@property (copy, nonatomic) NSString *title;
@property (nonatomic, copy) NSAttributedString *attributeTitle;

@property (nonatomic, strong) UIColor *titleLabelTextColor;
@property (nonatomic, strong) UIFont *titleLabelTextFont;
@property (nonatomic, strong) UIColor *titleLabelBackgroundColor;
@property (nonatomic, assign) CGFloat titleLabelHeight;
@property (nonatomic, assign) NSTextAlignment titleLabelTextAlignment;
@property (nonatomic, assign) BOOL textScrollEnable;

@property (nonatomic, assign) BOOL isOnlyOneLoop;

@property (nonatomic, assign) BOOL hasConfigured;

Expand Down
85 changes: 62 additions & 23 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@

#import "SDCollectionViewCell.h"
#import "UIView+SDExtension.h"
#define defaultWidth self.frame.size.width //默认label的宽度 超过则滚动
#define defaultInterval 3.5 //默认时间间隔
#define delayInterval 1.0 //先定一段时间 延迟滚动

@implementation SDCollectionViewCell
{
@implementation SDCollectionViewCell{
__weak UILabel *_titleLabel;
}


- (instancetype)initWithFrame:(CGRect)frame
{
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self setupImageView];
[self setupTitleLabel];
Expand All @@ -49,60 +50,91 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

- (void)setTitleLabelBackgroundColor:(UIColor *)titleLabelBackgroundColor
{
- (void)setTitleLabelBackgroundColor:(UIColor *)titleLabelBackgroundColor{
_titleLabelBackgroundColor = titleLabelBackgroundColor;
_titleLabel.backgroundColor = titleLabelBackgroundColor;
}

- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor
{
- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor{
_titleLabelTextColor = titleLabelTextColor;
_titleLabel.textColor = titleLabelTextColor;
}

- (void)setTitleLabelTextFont:(UIFont *)titleLabelTextFont
{
- (void)setTitleLabelTextFont:(UIFont *)titleLabelTextFont{
_titleLabelTextFont = titleLabelTextFont;
_titleLabel.font = titleLabelTextFont;
}

- (void)setupImageView
{
- (void)setupImageView{
UIImageView *imageView = [[UIImageView alloc] init];
_imageView = imageView;
[self.contentView addSubview:imageView];
}

- (void)setupTitleLabel
{
UILabel *titleLabel = [[UILabel alloc] init];
- (void)setupTitleLabel{
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, defaultWidth, self.frame.size.height)];
_titleLabel = titleLabel;
_titleLabel.hidden = YES;
_titleLabel.numberOfLines = 1;
[self.contentView addSubview:titleLabel];
}

- (void)setTitle:(NSString *)title
{
- (void)setTitle:(NSString *)title{
_title = [title copy];
_titleLabel.text = [NSString stringWithFormat:@" %@", title];
_titleLabel.text = [NSString stringWithFormat:@"%@", title];
if (_titleLabel.hidden) {
_titleLabel.hidden = NO;
}

if (self.textScrollEnable ) {
CGFloat width = [self boundingWidthWithString:_titleLabel.text withFont:_titleLabelTextFont withMaxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)].width;
_titleLabel.frame = CGRectMake(0, 0, width, self.frame.size.height);

[UIView animateWithDuration:defaultInterval delay:delayInterval options:UIViewAnimationOptionTransitionNone animations:^{
if (width>defaultWidth) {
_titleLabel.frame = CGRectMake(defaultWidth-width, 0, width, self.frame.size.height);
}
} completion:^(BOOL finished) {
}];
}
}

-(void)setTitleLabelTextAlignment:(NSTextAlignment)titleLabelTextAlignment
{
- (void)setAttributeTitle:(NSAttributedString *)attributeTitle {
_attributeTitle = [attributeTitle copy];
if ([attributeTitle isKindOfClass:[NSAttributedString class]]) {
_titleLabel.attributedText = attributeTitle;
}
if (_titleLabel.hidden) {
_titleLabel.hidden = NO;
}

if (self.textScrollEnable ) {
CGFloat width = [self boundingWidthWithString:_titleLabel.text withFont:_titleLabelTextFont withMaxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)].width;
_titleLabel.frame = CGRectMake(0, 0, width, self.frame.size.height);

[UIView animateWithDuration:defaultInterval delay:delayInterval options:UIViewAnimationOptionTransitionNone animations:^{
if (width>defaultWidth) {
_titleLabel.frame = CGRectMake(defaultWidth-width, 0, width, self.frame.size.height);
}
} completion:^(BOOL finished) {
}];
}
}

-(void)setTitleLabelTextAlignment:(NSTextAlignment)titleLabelTextAlignment{
_titleLabelTextAlignment = titleLabelTextAlignment;
_titleLabel.textAlignment = titleLabelTextAlignment;
}

- (void)layoutSubviews
{
- (void)layoutSubviews{
[super layoutSubviews];

if (self.onlyDisplayText) {
_titleLabel.frame = self.bounds;
CGFloat width = [self boundingWidthWithString:_titleLabel.text withFont:_titleLabelTextFont withMaxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)].width;
CGRect frame = _titleLabel.frame;
frame.size = CGSizeMake(width, self.frame.size.height);
_titleLabel.frame = frame;

} else {
_imageView.frame = self.bounds;
CGFloat titleLabelW = self.sd_width;
Expand All @@ -111,6 +143,13 @@ - (void)layoutSubviews
CGFloat titleLabelY = self.sd_height - titleLabelH;
_titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
}

}

-(CGSize)boundingWidthWithString:(NSString *)string withFont:(UIFont *)Font withMaxSize:(CGSize)MaxSize
{
CGRect rect = [string boundingRectWithSize:MaxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:Font} context:nil];
return rect.size;
}

@end
47 changes: 22 additions & 25 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ typedef enum {
SDCycleScrollViewPageContolStyleNone // 不显示pagecontrol
} SDCycleScrollViewPageContolStyle;

typedef enum : NSUInteger {
SDDisplayTypeNormalText, // 显示正常文字
SDDisplayTypeAttributeText, // 显示attribute文字
} SDDisplayType;

@class SDCycleScrollView;

@protocol SDCycleScrollViewDelegate <NSObject>
Expand All @@ -58,21 +63,6 @@ typedef enum {
/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index;






// 不需要自定义轮播cell的请忽略以下两个的代理方法

// ========== 轮播自定义cell ==========

/** 如果你需要自定义cell样式,请在实现此代理方法返回你的自定义cell的class。 */
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view;

/** 如果你自定义了cell样式,请在实现此代理方法为你的cell填充数据以及其它一系列设置 */
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view;

@end

@interface SDCycleScrollView : UIView
Expand All @@ -91,7 +81,7 @@ typedef enum {
+ (instancetype)cycleScrollViewWithFrame:(CGRect)frame shouldInfiniteLoop:(BOOL)infiniteLoop imageNamesGroup:(NSArray *)imageNamesGroup;


////////////////////// 数据源API //////////////////////
////////////////////// 数据源接口 //////////////////////

/** 网络图片 url string 数组 */
@property (nonatomic, strong) NSArray *imageURLStringsGroup;
Expand All @@ -102,11 +92,7 @@ typedef enum {
/** 本地图片数组 */
@property (nonatomic, strong) NSArray *localizationImageNamesGroup;





////////////////////// 滚动控制API //////////////////////
////////////////////// 滚动控制接口 //////////////////////

/** 自动滚动间隔时间,默认2s */
@property (nonatomic, assign) CGFloat autoScrollTimeInterval;
Expand All @@ -131,7 +117,8 @@ typedef enum {
/** 解决viewWillAppear时出现时轮播图卡在一半的问题,在控制器viewWillAppear时调用此方法 */
- (void)adjustWhenControllerViewWillAppera;

////////////////////// 自定义样式API //////////////////////
////////////////////// 自定义样式接口 //////////////////////


/** 轮播图片的ContentMode,默认为 UIViewContentModeScaleToFill */
@property (nonatomic, assign) UIViewContentMode bannerImageViewContentMode;
Expand All @@ -148,12 +135,18 @@ typedef enum {
/** 只展示文字轮播 */
@property (nonatomic, assign) BOOL onlyDisplayText;

/** 文字超出宽度时是否支持滚动 */
@property (nonatomic, assign) BOOL textScrollEnable;

/** pagecontrol 样式,默认为动画样式 */
@property (nonatomic, assign) SDCycleScrollViewPageContolStyle pageControlStyle;

/** 分页控件位置 */
@property (nonatomic, assign) SDCycleScrollViewPageContolAliment pageControlAliment;

/** 文字显示样式 */
@property (nonatomic, assign) SDDisplayType displayType;

/** 分页控件距离轮播图的底部间距(在默认间距基础上)的偏移量 */
@property (nonatomic, assign) CGFloat pageControlBottomOffset;

Expand Down Expand Up @@ -190,16 +183,20 @@ typedef enum {
/** 轮播文字label对齐方式 */
@property (nonatomic, assign) NSTextAlignment titleLabelTextAlignment;

/** 滚动手势禁用(文字轮播较实用) */
- (void)disableScrollGesture;
/** 定时器拿出来启动暂停 */
@property (nonatomic, weak) NSTimer *timer ;


////////////////////// 清除缓存API //////////////////////
////////////////////// 清除缓存接口 //////////////////////

/** 清除图片缓存(此次升级后统一使用SDWebImage管理图片加载和缓存) */
+ (void)clearImagesCache;

/** 清除图片缓存(兼容旧版本方法) */
- (void)clearCache;

- (void)invalidateTimer;

- (void)setupTimer;

@end
Loading