Skip to content

Commit 96a58d8

Browse files
author
沙少盼
committed
处理了文字在高清屏幕失真的问题
1 parent 8f35c73 commit 96a58d8

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

SPGuidePage/GuideCoverView.m

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,26 @@ - (void)layoutTitleView:(UILabel *)lab LoaderItem:(LoaderItemModel *)model dista
258258
}
259259

260260
}
261-
- (UIImage*) imageWithUIView:(UIView*) view
261+
//把其他控件都转成image
262+
- (UIImage*) imageWithUIView:(UIView*) v
262263
{
263-
UIGraphicsBeginImageContext(view.bounds.size);
264-
CGContextRef ctx = UIGraphicsGetCurrentContext();
265-
[view.layer renderInContext:ctx];
266-
UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
264+
//method 1:高清屏幕,文字会失真
265+
// UIGraphicsBeginImageContext(view.bounds.size);
266+
// CGContextRef ctx = UIGraphicsGetCurrentContext();
267+
// [view.layer renderInContext:ctx];
268+
// UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
269+
// UIGraphicsEndImageContext();
270+
// return tImage;
271+
272+
//method 2:处理了失真问题
273+
CGSize s = v.bounds.size;
274+
// 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
275+
UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
276+
[v.layer renderInContext:UIGraphicsGetCurrentContext()];
277+
UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
267278
UIGraphicsEndImageContext();
268-
return tImage;
279+
return image;
280+
269281
}
270282
- (void)removeAllSubLayers{
271283
for (CALayer *layer in self.layer.sublayers) {

SPGuidePage/HighLightRegionModel.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
#import <Foundation/Foundation.h>
1010
#import <CoreGraphics/CoreGraphics.h>
11-
11+
//镂空形状
1212
typedef NS_ENUM(NSInteger,BezierPathType) {
13-
Circle = 1,
14-
Oval,
15-
RoundedRect,
16-
DottedLineRoundedRect
13+
Circle = 1,//
14+
Oval,//椭圆
15+
RoundedRect,//矩形(可带圆角)
16+
DottedLineRoundedRect//虚线边框,中间不镂空
1717
};
1818

1919
@interface HighLightRegionModel : NSObject

SPGuidePage/ViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ - (void)viewDidLoad {
2727

2828
LinkImageModel *link = [LinkImageModel initWithStyle:LinkImageStyleDefult CustomImage:nil Position:LinkImagePositionRightOver OffsetX:0 OffsetY:0];
2929
HighLightRegionModel *circle = [HighLightRegionModel initWith:Circle Rect:self.btn1.frame Radius:0];
30-
TextModel *title = [TextModel initWithFont:[UIFont systemFontOfSize:18] text:@"我我我我我我我我我我我我我我" Alignment:TextAlignmentRight];
30+
TextModel *title = [TextModel initWithFont:[UIFont systemFontOfSize:18] text:@"我是大娃,会喷火" Alignment:TextAlignmentRight];
3131
LoaderItemModel *itemCircle = [LoaderItemModel initWithLink:link Title:title Region:circle];
3232

3333

@@ -42,7 +42,7 @@ - (void)viewDidLoad {
4242

4343
HighLightRegionModel *LineroundedRect = [HighLightRegionModel initWith:DottedLineRoundedRect Rect:self.btn4.frame Radius:3];
4444
LinkImageModel *link2 = [LinkImageModel initWithStyle:LinkImageStyleTortuousArrow CustomImage:nil Position:LinkImagePositionLeftUnder OffsetX:0 OffsetY:0];
45-
TextModel *title1 = [TextModel initWithFont:[UIFont systemFontOfSize:18] text:@"你你你你你你你你你你你你你你你你" Alignment:TextAlignmentLeft];
45+
TextModel *title1 = [TextModel initWithFont:[UIFont systemFontOfSize:18] text:@"我是二娃,会洒水" Alignment:TextAlignmentLeft];
4646
LoaderItemModel *itemLineroundedRect = [LoaderItemModel initWithLink:link2 Title:title1 Region:LineroundedRect];
4747
GuideCoverView *guideV = [[GuideCoverView alloc]initWithItems:@[itemOval,itemCircle,itemRounded,itemLineroundedRect,itemImage]];
4848
[guideV showInView:self.view];

0 commit comments

Comments
 (0)