-
.h文件
#import <UIKit/UIKit.h> /**滑桿*/ @interface YJL_Slider : UISlider @property(nonatomic , assign) CGFloat sliderHight; //滑條的高度 //初始化方法 -(instancetype)initWithFrame:(CGRect)frame andSliderHight:(CGFloat)sliderHight; @end
-
.m文件
#import "YJL_Slider.h" #define thumbBound_x 10 #define thumbBound_y 20 @implementation YJL_Slider { CGRect lastBounds; } -(instancetype)initWithFrame:(CGRect)frame andSliderHight:(CGFloat)sliderHight{ if (self = [super initWithFrame:frame]) { _sliderHight = sliderHight; } return self; } -(instancetype)init{ if (self = [super init]) { // } return self; } -(CGRect)trackRectForBounds:(CGRect)bounds{ if (_sliderHight == 0.00) { _sliderHight = 4; } return CGRectMake(0, 0, self.frame.size.width, _sliderHight); } //- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value{ // //y軸方向改變手勢范圍 // rect.origin.y = rect.origin.y - 10; // rect.size.height = rect.size.height + 20; // // // rect.origin.x = rect.origin.x - 10; // rect.size.width = rect.size.width + 20; // return CGRectInset ([super thumbRectForBounds:bounds trackRect:rect value:value], 10 ,10); //} - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value{ rect.origin.x = rect.origin.x; rect.size.width = rect.size.width ; CGRect result = [super thumbRectForBounds:bounds trackRect:rect value:value]; lastBounds = result; return result; } //滑桿上的點(diǎn)擊事件 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{ UIView *result = [super hitTest:point withEvent:event]; if ((point.y >= -thumbBound_y) && (point.y < lastBounds.size.height + thumbBound_y)) { float value = 0.0; value = point.x - self.bounds.origin.x; value = value/self.bounds.size.width; value = value < 0? 0 : value; value = value > 1? 1: value; value = value * (self.maximumValue - self.minimumValue) + self.minimumValue; [self setValue:value animated:YES]; } return result;
}
//擴(kuò)大觸摸點(diǎn)的響應(yīng)范圍 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{ BOOL result = [super pointInside:point withEvent:event]; if (!result && point.y > -10) { if ((point.x >= lastBounds.origin.x - thumbBound_x) && (point.x <= (lastBounds.origin.x + lastBounds.size.width + thumbBound_x)) && (point.y < (lastBounds.size.height + thumbBound_y))) { result = YES; } } return result; } @end
UISlider 定制
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門漩氨,熙熙樓的掌柜王于貴愁眉苦臉地迎上來西壮,“玉大人,你說我怎么就攤上這事叫惊】钋啵” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵霍狰,是天一觀的道長抡草。 經(jīng)常有香客問我饰及,道長,這世上最難降的妖魔是什么康震? 我笑而不...
- 正文 為了忘掉前任燎含,我火速辦了婚禮,結(jié)果婚禮上腿短,老公的妹妹穿的比我還像新娘屏箍。我一直安慰自己,他們只是感情好橘忱,可當(dāng)我...
- 文/花漫 我一把揭開白布赴魁。 她就那樣靜靜地躺著,像睡著了一般钝诚。 火紅的嫁衣襯著肌膚如雪颖御。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼盔腔,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了月褥?” 一聲冷哼從身側(cè)響起弛随,我...
- 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎宁赤,沒想到半個(gè)月后舀透,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡决左,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年愕够,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片佛猛。...
- 正文 年R本政府宣布,位于F島的核電站幻锁,受9級特大地震影響凯亮,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜哄尔,卻給世界環(huán)境...
- 文/蒙蒙 一假消、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧岭接,春花似錦置谦、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽瘟栖。三九已至葵擎,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間半哟,已是汗流浹背酬滤。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長得像戒良,于是被迫代替她去往敵國和親体捏。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 1糯崎、禁止手機(jī)睡眠[UIApplication sharedApplication].idleTimerDisabl...
- 1几缭、設(shè)置UILabel行間距 NSMutableAttributedString* attrString = [[...
- 1、設(shè)置UILabel行間距 NSMutableAttributedString* attrString = [[...
- 一沃呢、設(shè)置 document.domain 原理:相同主域名下不同子域頁面年栓,通過設(shè)置document.domain讓...