有没有人知道任何会复制iOS7风格模糊视图的控件.
我在假设可以有某种UIView子类来复制行为.
我在谈论这些类型的视图,它们将背景模糊得非常厚,以便它们从背景视图中获得拉动效果.


我如何将CGRect对象存储在NSMutableArray中,然后再检索它们?
我想要的只是在我的白色UILabel文本周围的一个像素黑色边框.
我使用下面的代码完成了UILabel的子类化,我从几个相关的在线示例中笨拙地拼凑而成.并且它工作但它非常非常慢(除了在模拟器上)并且我无法让它垂直居中文本(因此我暂时硬编码了最后一行的y值).哈啊!
void ShowStringCentered(CGContextRef gc, float x, float y, const char *str) {
CGContextSetTextDrawingMode(gc, kCGTextInvisible);
CGContextShowTextAtPoint(gc, 0, 0, str, strlen(str));
CGPoint pt = CGContextGetTextPosition(gc);
CGContextSetTextDrawingMode(gc, kCGTextFillStroke);
CGContextShowTextAtPoint(gc, x - pt.x / 2, y, str, strlen(str));
}
- (void)drawRect:(CGRect)rect{
CGContextRef theContext = UIGraphicsGetCurrentContext();
CGRect viewBounds = self.bounds;
CGContextTranslateCTM(theContext, 0, viewBounds.size.height);
CGContextScaleCTM(theContext, 1, -1);
CGContextSelectFont (theContext, "Helvetica", viewBounds.size.height, kCGEncodingMacRoman);
CGContextSetRGBFillColor (theContext, 1, 1, 1, 1);
CGContextSetRGBStrokeColor (theContext, 0, 0, 0, 1);
CGContextSetLineWidth(theContext, 1.0);
ShowStringCentered(theContext, rect.size.width / 2.0, 12, [[self text] cStringUsingEncoding:NSASCIIStringEncoding]);
} …Run Code Online (Sandbox Code Playgroud) 我在草图中设计了UI元素,其中一个具有模糊1和传播0的阴影.我查看了视图图层属性的文档,图层没有任何名为spread或blur的东西,或者任何等效的东西(唯一的控件是only shadowOpacity)如何控制模糊和传播之类的东西?
编辑:
以下是Sketch中的设置:
这就是我希望我的阴影看起来像:
我的代码如下:
func setupLayer(){
view.layer.cornerRadius = 2
view.layer.shadowColor = Colors.Shadow.CGColor
view.layer.shadowOffset = CGSize(width: 0, height: 1)
view.layer.shadowOpacity = 0.9
view.layer.shadowRadius = 5
}
Run Code Online (Sandbox Code Playgroud) 我有一个CGPoint称为点被分配触摸:
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
Run Code Online (Sandbox Code Playgroud)
我想将x坐标值放入我的控制台日志中:
NSLog(@"x: %s", point.x);
Run Code Online (Sandbox Code Playgroud)
当我使用它时,日志输出为:
x :( null)
我已经验证,使用调试器和变量监视调用此点时,该值不为null.
任何帮助,赞赏,
谢谢 // :)
我有以下CALayer:
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = CGRectMake(8, 57, 296, 30);
gradient.cornerRadius = 3.0f;
gradient.colors = [NSArray arrayWithObjects:(id)[RGB(130, 0, 140) CGColor], (id)[RGB(108, 0, 120) CGColor], nil];
[self.layer insertSublayer:gradient atIndex:0];
Run Code Online (Sandbox Code Playgroud)
我想为它添加内部阴影效果,但我不太清楚如何做到这一点.我想我会被要求在drawRect中绘制,但是这会在其他UIView对象之上添加图层,因为它应该是一些按钮背后的条形图,所以我不知道该怎么做?
我可以添加另一个图层,但是再次,不知道如何实现内部阴影效果(如下所示:

帮助赞赏......
在我看来,我有三个按钮.在viewDidLoad()中设置cornerRadus之后:button.layer.cornerRadius = 20我在日志中收到以下错误消息:
<Error>: CGContextSaveGState: invalid context 0x0.
If you want to see the backtrace, please set
CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Run Code Online (Sandbox Code Playgroud)
问题:
好的,我现在从消息中回溯了.这对我没有任何意义.一些帮助请...
Aug 7 14:27:00 <Error>: CGContextSaveGState: invalid context 0x0. Backtrace:
<-[UIStatusBarItemView updateContentsAndWidth]+33>
<-[UIStatusBarItemView initWithItem:data:actions:style:]+477>
<+[UIStatusBarItemView createViewForItem:withData:actions:foregroundStyle:]+134>
<-[UIStatusBarLayoutManager _createViewForItem:withData:actions:]+163>
<-[UIStatusBarLayoutManager _prepareEnabledItemType:withEnabledItems:withData:actions:itemAppearing:itemDisappearing:]+36
<-[UIStatusBarLayoutManager prepareEnabledItems:withData:actions:]+92>
<-[UIStatusBarForegroundView _setStatusBarData:actions:animated:]+797>
<-[UIStatusBarForegroundView setStatusBarData:actions:animated:]+332>
<__51-[UIStatusBar _prepareToSetStyle:animation:forced:]_block_invoke+360>
<+[UIView(Animation) performWithoutAnimation:]+65>
<-[UIStatusBar _prepareToSetStyle:animation:forced:]+866>
<-[UIStatusBar _requestStyleAttributes:animationParameters:forced:]+391>
<-[UIStatusBar requestStyle:animationParameters:forced:]+437>
<-[UIStatusBar requestStyle:animated:forced:]+90>
<-[UIStatusBar _evaluateServerRegistration]+250>
<__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke+590>
<-[UIView(Hierarchy) _postMovedFromSuperview:]+544>
<-[UIView(Internal) _addSubview:positioned:relativeTo:]+1967>
<-[UIStatusBarWindow setStatusBar:]+288>
<-[UIApplication _createStatusBarWithRequestedStyle:orientation:hidden:]+340>
<-[UIApplication _runWithMainScene:transitionContext:completion:]+950>
<-[UIApplication workspaceDidEndTransaction:]+188>
<-[FBSSerialQueue …Run Code Online (Sandbox Code Playgroud) 关于如何在App中显示PDF有很多资源UIView.我现在正在做的是从中创建一个PDF UIViews.
例如,我有一个UIView,与像Textviews子视图,UILabels,UIImages,所以我怎么能转换成一个大的 UIView整体,包括其所有子视图和subsubviews到PDF?
我查看过Apple的iOS参考资料.但是,它只涉及将文本/图像片段写入PDF文件.
我面临的问题是我想以PDF格式写入文件的内容很多.如果我将它们逐个写入PDF,那将是一项巨大的工作.这就是我寻找写入UIViewsPDF甚至位图的方法的原因.
我已经尝试过在Stack Overflow中从其他Q/A复制的源代码.但它只给我一个带有UIView边界大小的空白PDF .
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
// draws rect to the view and thus this is …Run Code Online (Sandbox Code Playgroud) 之前看到这个问过,但我的例子似乎没有用.
const CGFloat *toCol = CGColorGetComponents([[UIColor greenColor] CGColor]);
Run Code Online (Sandbox Code Playgroud)
使用GDB查看数组是空的.任何提示?
在我的iPad应用程序中,我想制作UIView占据屏幕重要部分的屏幕截图.不幸的是,子视图非常嵌套,因此需要很长时间才能制作屏幕截图并使页面随后变形.
有没有比"通常"更快的方式?
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我想避免缓存或重构我的观点.
core-graphics ×10
ios ×6
iphone ×5
cocoa-touch ×2
objective-c ×2
swift ×2
uiview ×2
calayer ×1
cgcolor ×1
cocoa ×1
nslog ×1
pdf ×1
performance ×1
quartz-core ×1
uicolor ×1
uiimage ×1
xcode ×1