小编moh*_*acs的帖子

如何在Swift语言中改变NSView的角半径

更改NSView的角半径应该是非常直接的但是我收到错误消息"致命错误:无法打开Optional.None".我是否有机会以10.9而不是10.10这样做,这是因为框架差异而发生的?或者代码错了.

class aRoundView: NSView {

    let cornerRad = 5.0

    init(frame: NSRect) {
        super.init(frame: frame)

        self.layer.cornerRadius  = cornerRad
    }

    override func drawRect(dirtyRect: NSRect)
    {
        super.drawRect(dirtyRect)
        NSColor.redColor().setFill()
        NSRectFill(dirtyRect)
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑

叫它

func applicationDidFinishLaunching(aNotification: NSNotification?) {

    let aView = mainViewTest(frame: NSMakeRect(0, 0, 100, 100))
    self.window.contentView.addSubview(aView)

}
Run Code Online (Sandbox Code Playgroud)

实际上不仅如此.任何使用self.layer的迭代都会给出相同的结果,backgroundcolor等.

macos cocoa nsview swift

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

XCode 5 中的相对行号

我刚刚开始使用 XCode。我已经安装了XVim插件来提供 Vim 键绑定。但是,我缺少打开相关行号的能力。在 vim 中,这是通过 完成的:set relativenumber,而在 Visual Studio 中,有一个插件。

XCode 5 有这样的东西吗?

vim xcode xcode5

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

获取用户输入并显示用户活着的mm/dd /年

我是iOS Dev的新手并且学习用户输入/输出.当用户被要求输入出生日期以查明用户活着多久时,我无法弄清楚如何显示mm/dd/yyyy的正确输出.

NSDate *actualDate = [[NSDate alloc]init];
NSDateComponents *comps = [[NSDateComponents alloc]init];

double getDays = [self.dayTextField.text doubleValue];
double getMonths = [self.monthTextField.text doubleValue];
double getYears = [self.yearTextField.text doubleValue];

NSCalendar *g = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *dateOfBirth = [g dateFromComponents:comps];

double secondsSinceEarlierDate = [actualDate timeIntervalSinceDate:dateOfBirth];

double minutes = secondsSinceEarlierDate/60;
double hours = minutes/60;
double weeks = days/7;

//Can not figure out these...
double days = hours/24;
double months = weeks * 0.229984378;
double years = months/12; 

self.showMonthsLabel.text = [@(months) stringValye];
self.showDaysLabel.text = [@(days) …
Run Code Online (Sandbox Code Playgroud)

objective-c ios

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

Objective-C 函数返回类型

在 c# 中,我可以创建函数可以返回任何类型的对象,例如

(ArrayList) funtionName()
{
    return ArrayList;
}
Run Code Online (Sandbox Code Playgroud)

这在 Obj-c 中可能吗?谢谢。

types object objective-c

0
推荐指数
1
解决办法
2519
查看次数

我设置页脚高度 0.0 仍然显示在 uitableview 中

为什么采用页脚视图?

-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
        return 16;
    return 16.0;
}


-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0;
}

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor=[UIColor redColor];
    return view;
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor=[UIColor yellowColor];
    return view;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

uitableview ios

0
推荐指数
1
解决办法
1285
查看次数

UIStoryboard中的iOS 8自定义选项卡栏控制器

我试图在iOS 8的UIStoryboard中使用swift创建自定义标签栏控制器(objective-c也没关系).所以,我计划使用这段代码.

let item0: UITabBarItem = UITabBarController().tabBar.items[0] as UITabBarItem
item0.setFinishedSelectedImage(selectedImage0, withFinishedUnselectedImage: unselectedImage0)
Run Code Online (Sandbox Code Playgroud)

但是,问题是setFinishedSelectedImage不再支持,我看到了这个错误.我该如何实施?

从iOS 7及更早版本开始不推荐使用的API在Swift中不可用

uitabbarcontroller uistoryboard swift ios8

0
推荐指数
1
解决办法
4235
查看次数