Skip to content

Commit

Permalink
新增选中字体加粗的效果
Browse files Browse the repository at this point in the history
  • Loading branch information
MJCIOS committed Dec 26, 2017
1 parent d64dd4f commit dd8e8d5
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//https://github.com/MJCIOS/MJCSegmentInterface
// https://github.com/MJCIOS/MJCSegmentInterface
//如果觉得好,麻烦点个星,谢谢大家支持,有啥问题加我QQ: 292251588 一起交流,我是菜菜..求大神指教
// MJCSegmentInterface.m
// MJCSegmentInterface
Expand Down Expand Up @@ -224,6 +224,7 @@ -(void)setJc_stylesTools:(MJCSegmentStylesTools *)jc_stylesTools
_titlesView.itemTextsEdgeInsets = jc_stylesTools.itemTextsEdgeInsets;
_titlesView.imageEffectStyles = jc_stylesTools.itemImageEffectStyles;
_titlesView.itemBackColor = jc_stylesTools.itemBackColor;
_titlesView.itemBackColorSelected = jc_stylesTools.itemBackColorSelected;
_titlesView.itemTextFontSize = jc_stylesTools.itemTextFontSize;
_titlesView.itemTextNormalColor = jc_stylesTools.itemTextNormalColor;
_titlesView.itemTextSelectedColor = jc_stylesTools.itemTextSelectedColor;
Expand All @@ -238,6 +239,7 @@ -(void)setJc_stylesTools:(MJCSegmentStylesTools *)jc_stylesTools
_titlesView.itemImageSize = jc_stylesTools.itemImageSize;
_titlesView.itemTitleNormalColorArray = jc_stylesTools.itemTextColorArrayNormal;
_titlesView.itemTitleSelectedColorArray = jc_stylesTools.itemTextColorArraySelected;
_titlesView.itemTextBoldFontSize = jc_stylesTools.itemTextBoldFontSize;

_titlesView.isIndicatorsAnimals = jc_stylesTools.indicatorsAnimalsEnabled;
_titlesView.isIndicatorFollow = jc_stylesTools.indicatorFollowEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ UIKIT_STATIC_INLINE MJCEdgeInsets MJCEdgeInsetsMake(CGFloat maxTop, CGFloat maxL
/** item图片效果样式 */
@property (nonatomic,copy,readonly) MJCSegmentStylesTools *(^jc_itemImageEffectStyles)(MJCImageEffectStyles);
@property (nonatomic,assign) MJCImageEffectStyles itemImageEffectStyles;

/** item背景颜色 */
@property (nonatomic,copy,readonly) MJCSegmentStylesTools *(^jc_itemBackColor)(UIColor *itemBackColor);
@property (nonatomic,strong,readonly) UIColor *itemBackColor;
/** item选中状态下的背景颜色 */
@property (nonatomic,copy,readonly) MJCSegmentStylesTools *(^jc_itemBackColorSelected)(UIColor *itemBackColorSelected);
@property (nonatomic,strong,readonly) UIColor *itemBackColorSelected;
/** item普通状态下文字颜色 */
@property (nonatomic,copy,readonly) MJCSegmentStylesTools *(^jc_itemTextNormalColor)(UIColor *itemTextNormalColor);
@property (nonatomic,strong,readonly) UIColor *itemTextNormalColor;
Expand All @@ -150,6 +152,9 @@ UIKIT_STATIC_INLINE MJCEdgeInsets MJCEdgeInsetsMake(CGFloat maxTop, CGFloat maxL
/** item文字大小 */
@property (nonatomic,copy,readonly) MJCSegmentStylesTools *(^jc_itemTextFontSize)(CGFloat itemTextFontSize);
@property (nonatomic,assign,readonly) CGFloat itemTextFontSize;
/** item文字加粗大小 */
@property (nonatomic,copy,readonly) MJCSegmentStylesTools *(^jc_itemTextBoldFontSize)(CGFloat itemTextBoldFontSize);
@property (nonatomic,assign) CGFloat itemTextBoldFontSize;
/** item普通状态下的图片 */
@property (nonatomic,copy,readonly) MJCSegmentStylesTools *(^jc_itemImageNormal)(UIImage *itemImageNormal);
@property (nonatomic,strong,readonly) UIImage *itemImageNormal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ +(instancetype)jc_initWithSegmentStylestoolsBlock:(void(^)(MJCSegmentStylesTools

}

-(MJCSegmentStylesTools *(^)(UIColor *))jc_itemBackColorSelected
{
return ^MJCSegmentStylesTools *(UIColor *itemBackColorSelected)
{
_itemBackColorSelected = itemBackColorSelected;
return self;
};
}

-(MJCSegmentStylesTools *(^)(UIColor *))jc_itemBackColor
{
return ^MJCSegmentStylesTools *(UIColor *itemBackColor)
Expand All @@ -261,6 +270,15 @@ +(instancetype)jc_initWithSegmentStylestoolsBlock:(void(^)(MJCSegmentStylesTools
};
}

-(MJCSegmentStylesTools *(^)(CGFloat))jc_itemTextBoldFontSize
{
return ^MJCSegmentStylesTools* (CGFloat itemTextBoldFontSize)
{
_itemTextBoldFontSize = itemTextBoldFontSize;
return self;
};
}

-(MJCSegmentStylesTools *(^)(UIColor *))jc_itemTextNormalColor
{
return ^MJCSegmentStylesTools *(UIColor *itemTextNormalColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import <UIKit/UIKit.h>

@interface MJCTabItem : UIButton

@property (nonatomic,strong) UIColor *itemBackColorSelected;
@property (nonatomic,copy) NSString *itemText;
@property (nonatomic,assign) CGFloat itemTextFontSize;
@property (nonatomic,strong) NSArray *itemTitleNormalColorArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ -(void)setItemImagesEdgeInsets:(UIEdgeInsets)itemImagesEdgeInsets
_topImageMargin = itemImagesEdgeInsets.top;
_bottomImageMargin = itemImagesEdgeInsets.bottom;
}
-(void)setItemBackColorSelected:(UIColor *)itemBackColorSelected
{
_itemBackColorSelected = itemBackColorSelected;
if (itemBackColorSelected) {
[self setBackgroundImage:[MJCCommontools jc_imageWithColor:itemBackColorSelected] forState:UIControlStateSelected];
}
}

-(void)setItemText:(NSString *)itemText
{
Expand Down Expand Up @@ -180,7 +187,9 @@ -(void)setItemBackNormalImage:(UIImage *)itemBackNormalImage
-(void)setItemBackSelectedImage:(UIImage *)itemBackSelectedImage
{
_itemBackSelectedImage = itemBackSelectedImage;
[self setBackgroundImage:itemBackSelectedImage forState:UIControlStateSelected];
if (itemBackSelectedImage) {
[self setBackgroundImage:itemBackSelectedImage forState:UIControlStateSelected];
}
}

-(void)setItemImageNormal:(UIImage *)itemImageNormal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef void(^TabitemArrBlock)(NSArray<MJCTabItem*>*tabItemArr);
@property (nonatomic,assign) NSInteger defaultShowItemCount;
@property (nonatomic,assign) NSInteger selectedSegmentIndex;
@property (nonatomic,strong) UIColor *itemBackColor;
@property (nonatomic,strong) UIColor *itemBackColorSelected;
@property (nonatomic,strong) UIImage *itemImageNormal;
@property (nonatomic,strong) UIImage *itemImageSelected;
@property (nonatomic,strong) NSArray *itemImageNormalArray;
Expand All @@ -48,6 +49,7 @@ typedef void(^TabitemArrBlock)(NSArray<MJCTabItem*>*tabItemArr);
@property (nonatomic,strong) UIColor *itemTextNormalColor;
@property (nonatomic,strong) UIColor *itemTextSelectedColor;
@property (nonatomic,assign) CGFloat itemTextFontSize;
@property (nonatomic,assign) CGFloat itemTextBoldFontSize;
@property (nonatomic,assign) CGSize itemImageSize;
@property(nonatomic,assign) BOOL isItemTitleTextHidden;
@property (nonatomic,assign) BOOL isFontGradient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ -(void)setupButton:(MJCTabItem *)tabbutton
tabbutton.itemText = _titlesArray[tabbutton.tag];
}
tabbutton.backgroundColor = _itemBackColor;
tabbutton.itemBackColorSelected = _itemBackColorSelected;
tabbutton.itemImageSize = _itemImageSize;
tabbutton.itemTextFontSize = _itemTextFontSize;
tabbutton.itemTitleNormalColor = _itemTextNormalColor;
Expand Down Expand Up @@ -383,6 +384,8 @@ -(void)setupClickAndScrollEndWith:(MJCTabItem *)titleButton
{
_selectedTag = titleButton.tag;



if (_titlesArray.count >=3 && self.contentSize.width > self.frame.size.width) {
[self setupTitleCenter:titleButton];
}
Expand Down Expand Up @@ -457,6 +460,10 @@ -(void)setupClickAndScrollEndWith:(MJCTabItem *)titleButton
}

[self setupIndicatorViewCenterAndWidth];

if (_itemTextBoldFontSize) {
titleButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:_itemTextBoldFontSize];
}
}

-(void)setupIndicatorViewCenterAndWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ -(void)setupSegmentWithTitlesArr:(NSArray *)titlesArr vcArr:(NSArray *)vcArr ima
jc_itemImageArrayNormal(imageNArr).
jc_itemImageArraySelected(imageSArr).
jc_ItemDefaultShowCount(5).
jc_itemBackImageSelected([MJCCommontools jc_imageWithColor:[[UIColor orangeColor] colorWithAlphaComponent:0.7]]).
jc_itemBackColorSelected([[UIColor orangeColor] colorWithAlphaComponent:0.7]).
jc_itemTextNormalColor([UIColor blackColor]).
jc_itemTextFontSize(13).
jc_childScollAnimalEnabled(YES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ -(void)setupInterfaceWithTitlesArr:(NSArray*)titlesArr vcArr:(NSArray*)vcArr
jc_itemTextSelectedColor([UIColor purpleColor]).
jc_itemSelectedSegmentIndex(3).
jc_ItemDefaultShowCount(6).
jc_itemTextFontSize(11).
jc_itemTextFontSize(13).
jc_indicatorStyles(MJCIndicatorItemTextStyle).
jc_indicatorsAnimalsEnabled(YES).
jc_titlesViewFrame(CGRectMake(0, 0, self.view.jc_width, 50));
Expand Down

0 comments on commit dd8e8d5

Please sign in to comment.