日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

IOS之代理文字点击变大变小

發(fā)布時(shí)間:2023/12/18 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS之代理文字点击变大变小 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

IOS之代理文字點(diǎn)擊變大變小


重點(diǎn)是掌握代理的使用,否則也失去次此意義

#import "ViewController.h" #import "AHLJFontSizePicker.h" #define kScreenW [UIScreen mainScreen].bounds.size.width @interface ViewController ()<AHLJFontSizePickerDelegate> @property (weak, nonatomic) IBOutlet UILabel *lbl; @end @implementation ViewController - (void)viewDidLoad {[super viewDidLoad];AHLJFontSizePicker *pickView = [[AHLJFontSizePicker alloc] initWithFrame:CGRectZero];pickView.delegate = self;pickView.frame = CGRectMake(0, 150, kScreenW, 80);pickView.backgroundColor = UIColor.systemTealColor;[self.view addSubview:pickView];} - (void)fontSizePickerDidBtnClick:(AHLJFontSizePicker *)picker didSetFontSize:(FontSizeEnum)fontSize{switch (fontSize) {case FontSizeSmall:self.lbl.font = [UIFont systemFontOfSize:11 weight:UIFontWeightBold];break;case FontSizeMiddle:self.lbl.font = [UIFont systemFontOfSize:15 weight:UIFontWeightBold];break;case FontSizeBig:self.lbl.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];break;case FontSizeSuperBig:self.lbl.font = [UIFont systemFontOfSize:22 weight:UIFontWeightBold];break;default:break;}} @end // // AHLJFontSizePicker.h // 圖片點(diǎn)擊文字變大或者變小 // // Created by lujun on 2021/10/20. //#import <UIKit/UIKit.h> @class AHLJFontSizePicker; typedef enum {FontSizeSmall = 0,FontSizeMiddle = 1,FontSizeBig = 2,FontSizeSuperBig = 3}FontSizeEnum; NS_ASSUME_NONNULL_BEGIN @protocol AHLJFontSizePickerDelegate <NSObject> -(void)fontSizePickerDidBtnClick:(AHLJFontSizePicker *)picker didSetFontSize:(FontSizeEnum)fontSize; @end @interface AHLJFontSizePicker : UIView @property(nonatomic,weak)id<AHLJFontSizePickerDelegate> delegate; @end NS_ASSUME_NONNULL_END #define kBtnCount 4 #import "AHLJFontSizePicker.h" #define btnH1 30 #define btnY1 5 #define btnW1 self.frame.size.width / btnCount @interface AHLJFontSizeButton : UIButton @end @implementation AHLJFontSizeButton - (instancetype)initWithFrame:(CGRect)frame{self = [super initWithFrame:frame];if(self){self.adjustsImageWhenHighlighted = NO;self.imageView.contentMode = UIViewContentModeScaleAspectFit;}return self; } - (void)setHighlighted:(BOOL)highlighted{} @end @interface AHLJFontSizePicker() @property(nonatomic,weak)AHLJFontSizeButton *selectedButton; @property(nonatomic,weak)UIImageView *topLine; @property(nonatomic,weak)UIImageView *bottomLine; @property(nonatomic,weak)UIImageView *slider; @end @implementation AHLJFontSizePicker - (UIImageView *)topLine{if(!_topLine){UIImageView *topLineImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"正文字號(hào)-滑條紅"]];_topLine = topLineImg;[self addSubview:_topLine];}return _topLine; } - (void)drawRect:(CGRect)rect{[super drawRect:rect];CGFloat sW = [UIScreen mainScreen].bounds.size.width;CGFloat btnW = sW / kBtnCount;CGFloat btnY = 5;CGFloat btnH = 30;NSArray *arrNor = @[@"正文字號(hào)-小(默認(rèn))",@"正文字號(hào)-中(默認(rèn))",@"正文字號(hào)-大(默認(rèn))",@"正文字號(hào)-大+(默認(rèn))"];NSArray *arrSel = @[@"正文字號(hào)-小",@"正文字號(hào)-中",@"正文字號(hào)-大",@"正文字號(hào)-大+"];for(int i=0;i<kBtnCount;i++){AHLJFontSizeButton *btn = [[AHLJFontSizeButton alloc] initWithFrame:CGRectMake(i * btnW, btnY, btnW, btnH)];[btn setImage:[UIImage imageNamed:arrNor[i]] forState:UIControlStateNormal];[btn setImage:[UIImage imageNamed:arrSel[i]] forState:UIControlStateSelected];btn.tag = i;[self addSubview:btn];[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];}AHLJFontSizeButton *firstBtn = (AHLJFontSizeButton *)self.subviews.firstObject;AHLJFontSizeButton *lastBtn = (AHLJFontSizeButton *)self.subviews.lastObject;UIImageView *slider = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"正文字號(hào)-滑塊"]];[self addSubview:slider];self.slider = slider;UIImageView *bottomLine = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"正文字號(hào)-滑條"]];CGFloat bottomLineX = firstBtn.center.x - slider.frame.size.width*0.5;CGFloat bottomLineMaxX = lastBtn.center.x + slider.frame.size.width*0.5;CGFloat bottomY = 35 + 15;bottomLine.frame = CGRectMake(bottomLineX,bottomY , bottomLineMaxX - bottomLineX, 3);[self addSubview:bottomLine];self.bottomLine = bottomLine;slider.center = CGPointMake( firstBtn.center.x, bottomLine.center.y);[self btnClick:firstBtn]; } -(void)btnClick:(AHLJFontSizeButton *)btn{self.selectedButton.selected = NO;btn.selected = YES;self.selectedButton = btn;self.slider.center =CGPointMake(self.selectedButton.center.x, self.bottomLine.center.y);self.topLine.frame = CGRectMake(self.bottomLine.frame.origin.x, self.bottomLine.frame.origin.y, self.slider.center.x-self.slider.frame.size.width-7, 3);if([self.delegate respondsToSelector:@selector(fontSizePickerDidBtnClick:didSetFontSize:)]){[self.delegate fontSizePickerDidBtnClick:self didSetFontSize:(int)btn.tag];} } @end

https://e.coding.net/lujun1/wangyecebianlan/IOSSmallPictureAndBig.git

總結(jié)

以上是生活随笔為你收集整理的IOS之代理文字点击变大变小的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。