Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
@邻家的橘猫
Iosswift
提交
1f78e59c
I
Iosswift
项目概览
@邻家的橘猫
/
Iosswift
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iosswift
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1f78e59c
编写于
3月 03, 2019
作者:
J
John Hampton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adds an Image using tap gesture
上级
f22720d9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
2 deletion
+49
-2
iOSTemplate/Base.lproj/Main.storyboard
iOSTemplate/Base.lproj/Main.storyboard
+11
-1
iOSTemplate/Info.plist
iOSTemplate/Info.plist
+2
-0
iOSTemplate/ViewController.swift
iOSTemplate/ViewController.swift
+36
-1
未找到文件。
iOSTemplate/Base.lproj/Main.storyboard
浏览文件 @
1f78e59c
...
...
@@ -40,11 +40,15 @@
<action
selector=
"setDefaultLabelText:"
destination=
"BYZ-38-t0r"
eventType=
"touchUpInside"
id=
"fTO-ku-xZY"
/>
</connections>
</button>
<imageView
userInteractionEnabled=
"NO"
contentMode=
"scaleToFill"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
placeholderIntrinsicWidth=
"320"
placeholderIntrinsicHeight=
"320"
image=
"defaultPhoto"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"Rhj-yY-68e"
>
<imageView
contentMode=
"scaleToFill"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
placeholderIntrinsicWidth=
"320"
placeholderIntrinsicHeight=
"320"
image=
"defaultPhoto"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"Rhj-yY-68e"
>
<rect
key=
"frame"
x=
"0.0"
y=
"104.5"
width=
"320"
height=
"320"
/>
<gestureRecognizers/>
<constraints>
<constraint
firstAttribute=
"width"
secondItem=
"Rhj-yY-68e"
secondAttribute=
"height"
multiplier=
"1:1"
id=
"ACo-ke-FCa"
/>
</constraints>
<connections>
<outletCollection
property=
"gestureRecognizers"
destination=
"UAM-fK-D64"
appends=
"YES"
id=
"uEG-WL-m3E"
/>
</connections>
</imageView>
</subviews>
<constraints>
...
...
@@ -63,9 +67,15 @@
<connections>
<outlet
property=
"mealNameLabel"
destination=
"n9u-9b-TSl"
id=
"6WN-5O-Vth"
/>
<outlet
property=
"nameTextField"
destination=
"DYv-F4-28V"
id=
"GJa-MY-QZF"
/>
<outlet
property=
"photoImageView"
destination=
"Rhj-yY-68e"
id=
"4Ye-IM-GYI"
/>
</connections>
</viewController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"dkx-z0-nzr"
sceneMemberID=
"firstResponder"
/>
<tapGestureRecognizer
id=
"UAM-fK-D64"
>
<connections>
<action
selector=
"selectImageFromPhotoLibrary:"
destination=
"BYZ-38-t0r"
id=
"0va-3Q-L6u"
/>
</connections>
</tapGestureRecognizer>
</objects>
<point
key=
"canvasLocation"
x=
"-79.200000000000003"
y=
"133.5832083958021"
/>
</scene>
...
...
iOSTemplate/Info.plist
浏览文件 @
1f78e59c
...
...
@@ -41,5 +41,7 @@
<string>
UIInterfaceOrientationLandscapeLeft
</string>
<string>
UIInterfaceOrientationLandscapeRight
</string>
</array>
<key>
NSPhotoLibraryUsageDescription
</key>
<string>
Allows you to add photos to your meals.
</string>
</dict>
</plist>
iOSTemplate/ViewController.swift
浏览文件 @
1f78e59c
...
...
@@ -7,11 +7,12 @@
import
UIKit
class
ViewController
:
UIViewController
,
UITextFieldDelegate
{
class
ViewController
:
UIViewController
,
UITextFieldDelegate
,
UIImagePickerControllerDelegate
,
UINavigationControllerDelegate
{
// MARK: Properties
@IBOutlet
weak
var
nameTextField
:
UITextField
!
@IBOutlet
weak
var
mealNameLabel
:
UILabel
!
@IBOutlet
weak
var
photoImageView
:
UIImageView
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
@@ -31,7 +32,41 @@ class ViewController: UIViewController, UITextFieldDelegate {
mealNameLabel
.
text
=
textField
.
text
}
//MARK: UIImagePickerControllerDelegate
func
imagePickerControllerDidCancel
(
_
picker
:
UIImagePickerController
)
{
// Dismiss the picker if the user canceled.
dismiss
(
animated
:
true
,
completion
:
nil
)
}
func
imagePickerController
(
_
picker
:
UIImagePickerController
,
didFinishPickingMediaWithInfo
info
:
[
UIImagePickerController
.
InfoKey
:
Any
])
{
// The info dictionary may contain multiple representations of the image. You want to use the original.
guard
let
selectedImage
=
info
[
UIImagePickerController
.
InfoKey
.
originalImage
]
as?
UIImage
else
{
fatalError
(
"Expected a dictionary containing an image, but was provided the following:
\(
info
)
"
)
}
// Set photoImageView to display the selected image.
photoImageView
.
image
=
selectedImage
// Dismiss the picker.
dismiss
(
animated
:
true
,
completion
:
nil
)
}
// MARK: Actions
@IBAction
func
selectImageFromPhotoLibrary
(
_
sender
:
UITapGestureRecognizer
)
{
// Hide the keyboard.
nameTextField
.
resignFirstResponder
()
// UIImagePickerController is a view controller that lets a user pick media from their photo library.
let
imagePickerController
=
UIImagePickerController
()
// Only allow photos to be picked, not taken.
imagePickerController
.
sourceType
=
.
photoLibrary
// Make sure ViewController is notified when the user picks an image.
imagePickerController
.
delegate
=
self
present
(
imagePickerController
,
animated
:
true
,
completion
:
nil
)
}
@IBAction
func
setDefaultLabelText
(
_
sender
:
UIButton
)
{
mealNameLabel
.
text
=
"Default Text"
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录