小编Les*_*nel的帖子

是否可以在iOS Playground中加载故事板?

是否可以在iOS Playground中加载故事板?请按照以下问题中的步骤操作:

如何从iOS操场中的文件中实例化Storyboard?

编译Main.storyboard使用

ibtool --compile MainMenu.nib MainMenu.storyboard
Run Code Online (Sandbox Code Playgroud)

将其添加到Resources游乐场的文件夹中.然后尝试加载它:

let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
Run Code Online (Sandbox Code Playgroud)

这导致错误:

Playground execution aborted: Execution was interrupted, reason: signal SIGABRT.
Run Code Online (Sandbox Code Playgroud)

XCode 7.3.1甚至XCode 8是否支持此功能?

ios swift swift-playground

5
推荐指数
1
解决办法
2229
查看次数

将C#反射代码移植到Metro-Ui

我正在尝试移植使用反射的现有C#类(通用工厂),但我无法编译这段代码:

Type[] types = Assembly.GetAssembly(typeof(TProduct)).GetTypes();
foreach (Type type in types)
{
    if (!typeof(TProduct).IsAssignableFrom(type) || type == typeof(TProduct))
...
Run Code Online (Sandbox Code Playgroud)

我试着查看.NET Framework for Windows Metro Style AppsAssembly Class中的Reflection,在那里我发现了一个因为"使用System.Security.Permissions"而无法编译的示例.

c# reflection microsoft-metro windows-8 windows-runtime

3
推荐指数
1
解决办法
1157
查看次数

ios 6和ios 5.1之间的核心文本差异?

看来ios 5.1和ios 6之间的CoreText实现存在一些差异,您可以从这两个屏幕截图中看到:

ios 6: 在此输入图像描述

ios 5: 在此输入图像描述

首先,文本颜色未正确应用.似乎在ios 5.1上kCTForegroundColorAttributeName要求你给它一个CGColor,而在ios 6上,传递一个UIColor就足够了.所以我通过将代码更改为:

[attributes setObject:(id)[color CGColor] 
               forKey:(NSString*)kCTForegroundColorAttributeName];
Run Code Online (Sandbox Code Playgroud)

其次,段落间距有点偏."视线"和"根据"之间的距离是11像素对25像素(在屏幕截图中测量).在两种情况下,段落间距都设置为5:

NSMutableData *styleSettingsArray = [NSMutableData data];
CGFloat spaceBefore,spaceAfter;
...
CTParagraphStyleSetting styleSettingB = {kCTParagraphStyleSpecifierParagraphSpacingBefore   ,sizeof(CGFloat),&spaceBefore};
CTParagraphStyleSetting styleSettingA = {kCTParagraphStyleSpecifierParagraphSpacing         ,sizeof(CGFloat),&spaceAfter};
[styleSettingsArray appendBytes:&styleSettingB length:sizeof(styleSettingB)];
[styleSettingsArray appendBytes:&styleSettingA length:sizeof(styleSettingA)];
...
if(styleSettingsArray.length > 0)
{
    CTParagraphStyleRef paragraphStyleRef = CTParagraphStyleCreate([styleSettingsArray bytes], [styleSettingsArray length] / sizeof(CTParagraphStyleSetting));
    [dictionary setObject:(__bridge id)(paragraphStyleRef) forKey:(NSString*)kCTParagraphStyleAttributeName];
    CFRelease(paragraphStyleRef);
}
Run Code Online (Sandbox Code Playgroud)

paragraphStyleRef在控制台中的描述:

iOS 6:
CTParagraphStyle:
base writing direction = -1, alignment = 3, line break mode = …
Run Code Online (Sandbox Code Playgroud)

core-text ios ios5 ios6

3
推荐指数
1
解决办法
1413
查看次数

在 iPad 上将 UIActivityViewController 显示为表单

我试图在不使用弹出窗口的情况下显示共享表,即没有源视图或箭头。

这是我的代码,从基本的单视图应用程序开始:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func didTapShare(_ sender: UIButton) {
        let activity = UIActivityViewController(activityItems: ["banana"], applicationActivities: nil)
        
        if UIDevice.current.userInterfaceIdiom == .pad {
            activity.modalPresentationStyle = .formSheet
//            activity.preferredContentSize = CGSize(width: 400, height: 400)
        }
        
        present(activity, animated: true, completion: nil)
    }
    
}

Run Code Online (Sandbox Code Playgroud)

这当然是崩溃的

"UIPopoverPresentationController (<UIPopoverPresentationController: 0x7fce07507900>) should have a non-nil sourceView or barButtonItem set before the presentation occurs."
Run Code Online (Sandbox Code Playgroud)

但我不希望它看起来像弹出窗口,或者有箭头——我希望它显示为表单,位于屏幕中间。

这是它在“照片”应用程序中的外观:

照片表格

ios uiactivityviewcontroller

3
推荐指数
1
解决办法
683
查看次数

iOS iVar名为"Size"语法错误?

拿这个代码:

@interface SomeClass:NSObject
{
@private
  NSString* Size;
}

@property NSString* Size;

@end

--------------------------

@implementation SomeClass
@synthesize Size;

- (void) something
{
  Size = @"syntax error : Expected identifier or '(' ";
  self.Size = @"works ok";
}

@end
Run Code Online (Sandbox Code Playgroud)

为什么这是语法错误?"Size"是保留字还是已在NSSObject中定义?我在两个单独的项目上得到了错误......

iphone xcode objective-c ios

2
推荐指数
1
解决办法
90
查看次数