[英]How to achieve horizontal scaling view in iOS?
I have used TSRDialScrollView library to do as per the design requirement in my code. 我已使用TSRDialScrollView库按照代码中的设计要求进行操作。
But couldn't solve few issues. 但是解决不了几个问题。
Referred from below link : 从以下链接引用:
https://www.cocoacontrols.com/controls/trsdialscrollview https://www.cocoacontrols.com/controls/trsdialscrollview
I have made few changes in my code 我对代码进行了一些更改
-> To clear background color ->清除背景色
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor clearColor] set];
CGContextFillRect(context, rect);
But it is displaying black color. 但是它显示黑色。
-> Setting label after view is inverted ->视图倒置后设置标签
- (void)drawLabelWithContext:(CGContextRef)context
atPoint:(CGPoint)point
text:(NSString *)text
fillColor:(UIColor *)fillColor
strokeColor:(UIColor *)strokeColor {
// We want the label to be centered on the specified x value
NSInteger label_y = ((point.y-100) - (boundingBox.width / 2));
}
-> Inverted the whole view by changing minor and major tick length to negative in code. ->通过将代码的次要和主要记号长度更改为负来反转整个视图。
- (void)drawTicksWithContext:(CGContextRef)context atX:(long)x
{
CGPoint point = CGPointMake(x, self.frame.size.height);
CGContextSetShadowWithColor(
context,
self.shadowOffset,
self.shadowBlur,
self.shadowColor.CGColor);
if ([self isMajorTick:x]) {
[self drawMajorTickWithContext:context
atPoint:point
withColor:self.majorTickColor
width:self.majorTickWidth
length:-self.majorTickLength];
// Draw the text
//
// 1) Take the existing position and subtract off the lead spacing
// 2) Divide by the minor ticks to get the major number
// 3) Add the minimum to get the current value
//
int value = (point.x - self.leading) / self.minorTickDistance + _minimum;
NSString *text = [NSString stringWithFormat:@"%i", value];
[self drawLabelWithContext:context
atPoint:point
text:text
fillColor:self.labelFillColor
strokeColor:self.labelStrokeColor];
} else {
CGContextSaveGState(context);
[self drawMinorTickWithContext:context
atPoint:point
withColor:self.minorTickColor
width:self.minorTickWidth
length:-self.minorTickLength];
// Restore the context
CGContextRestoreGState(context);
}
}
I want scaling to be done as shown below. 我希望按如下所示完成缩放。
1) By adjusting the offset, the view of scrollview should be in middle.(i,e when it is scrolled to minimum value the position of 0 is not at the middle of the view). 1)通过调整偏移量,scrollview的视图应位于中间(即,当滚动到最小值时,0的位置不在视图的中间)。
2) I want the background color to be clear color. 2)我希望背景颜色是清晰的颜色。
3) As per the design how to set red color to the middle line which is to be fixed? 3)根据设计,如何在要固定的中线设置红色?
4) How to display light grey color in the middle as shown in image ? 4)如何如图所示在中间显示浅灰色?
I appreciate your help, and please suggest how to achieve this,really i need to complete this task it is very much needed. 感谢您的帮助,并建议如何实现此目标,确实我需要完成此任务,这是非常必要的。
Thanks in advance. 提前致谢。
TRSDialView.m
TRSDialView.m
file :- 档案:-
In - (instancetype)initWithFrame:(CGRect)frame
add self.opaque = NO;
在
- (instancetype)initWithFrame:(CGRect)frame
添加self.opaque = NO;
Inside - (void)drawRect:(CGRect)rect
method add following code below CGContextRef context = UIGraphicsGetCurrentContext();
内部
- (void)drawRect:(CGRect)rect
方法在CGContextRef context = UIGraphicsGetCurrentContext();
下面添加以下代码CGContextRef context = UIGraphicsGetCurrentContext();
code of line 行代码
// Fill the background
CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor);
// CGContextFillRect(context, rect);
CGContextClearRect(context, rect);
The above code will clear background color. 上面的代码将清除背景色。
To adjust offset
add width constraint
to TRSDialView
in Storyboard
要调整
offset
, TRSDialView
在Storyboard
为TRSDialView
添加width constraint
The red line and grey view can be added as subview
in storyboard
红线和灰色视图可以添加为
storyboard
subview
中的subview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.