Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
ShorthandMaster
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lmj
ShorthandMaster
Commits
dae5e19a
Commit
dae5e19a
authored
Sep 27, 2020
by
zhangzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图文的新增和查看
parent
86a17ba3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
62 deletions
+56
-62
SHInputController.swift
ShorthandMaster/Input/Controller/SHInputController.swift
+54
-60
SHInputViewModel.swift
ShorthandMaster/Input/ViewModel/SHInputViewModel.swift
+2
-2
No files found.
ShorthandMaster/Input/Controller/SHInputController.swift
View file @
dae5e19a
...
@@ -63,67 +63,61 @@ class SHInputController: SHBaseViewController
...
@@ -63,67 +63,61 @@ class SHInputController: SHBaseViewController
self
.
shInputView
.
bottomView
.
stopAudioButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedStopAudioButton(sender:)
)
,
for
:
UIControl
.
Event
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
stopAudioButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedStopAudioButton(sender:)
)
,
for
:
UIControl
.
Event
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
keyboardButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedKeyboardButton(sender:)
)
,
for
:
UIControl
.
Event
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
keyboardButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedKeyboardButton(sender:)
)
,
for
:
UIControl
.
Event
.
touchUpInside
)
// TODO: 先做新增, 查看和编辑稍后再做
// 有记录显示记录
// // 有记录显示记录
if
dataModel
.
rename
.
length
>
0
// if UserDefaults.standard.value(forKey: "InputRecord") != nil
{
// {
self
.
shInputView
.
placeholder
.
isHidden
=
true
// self.shInputView.placeholder.isHidden = true
//
let
attributeString
:
NSMutableAttributedString
=
NSMutableAttributedString
()
// let historyDic : [String : Any] = UserDefaults.standard.value(forKey: "InputRecord") as! [String : Any]
//
let
titleString
=
NSAttributedString
(
string
:
self
.
dataModel
.
rename
,
attributes
:
(
SHInputViewModel
.
titleAttributes
()
as!
[
NSAttributedString
.
Key
:
Any
]))
// let attributeString : NSMutableAttributedString = NSMutableAttributedString()
attributeString
.
append
(
titleString
)
//
// let titleString = NSAttributedString(string: historyDic["title"] as! String, attributes: (SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any]))
let
contentString
=
NSAttributedString
(
string
:
self
.
dataModel
.
txt
,
attributes
:
SHInputViewModel
.
contentAttributes
()
as?
[
NSAttributedString
.
Key
:
Any
])
// attributeString.append(titleString)
attributeString
.
append
(
contentString
)
//// self.viewModel.title = titleString.string
// self.dataModel.rename = titleString.string
let
imagesPath
:
Array
=
self
.
dataModel
.
imagesPath
//
let
imagesIndex
:
Array
=
self
.
dataModel
.
imagesIndex
// let contentString = NSAttributedString(string: historyDic["content"] as! String, attributes: SHInputViewModel.contentAttributes() as? [NSAttributedString.Key : Any])
// attributeString.append(contentString)
var
i
=
0
//
// let imageArray : Array = historyDic["imageArray"] as! Array<[String : Any]>
for
imagePath
:
String
in
imagesPath
//
{
// for imageDictionary : [String : Any] in imageArray
let
image
:
UIImage
=
UIImage
(
contentsOfFile
:
DocumentPath
+
imagePath
)
??
UIImage
()
// {
// let imageDataString : String = imageDictionary["imageData"] as! String
// 调整图片大小, 宽相同, 高随比例变化
//
let
newWidth
=
kScreenWidth
-
20
*
2
// let imageData : Data = NSData(base64Encoded: imageDataString, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)! as Data
let
newHeight
=
newWidth
*
image
.
size
.
height
/
image
.
size
.
width
// let image : UIImage = UIImage(data: imageData)!
let
newSize
=
CGSize
(
width
:
newWidth
,
height
:
newHeight
)
//
// // 调整图片大小, 宽相同, 高随比例变化
let
imageLocation
:
Int
=
imagesIndex
[
i
]
// let newWidth = kScreenWidth - 20 * 2
// let newHeight = newWidth * image.size.height / image.size.width
// let newSize = CGSize(width: newWidth, height: newHeight)
//
// let imageLocation : Int = imageDictionary["imageLocation"] as! Int
//
//
// let attachment = NSTextAttachment.init()
// attachment.image = image
// attachment.bounds = CGRect(origin: CGPoint.zero, size: newSize)
// let imageString = NSMutableAttributedString(attachment: attachment)
//
// // 设置图片文字属性
// imageString.addAttributes((SHInputViewModel.contentAttributes() as? [NSAttributedString.Key : Any])!, range: NSRange(location: 0, length: imageString.length))
// // 设置图片间距
// let paragraphStyle = NSMutableParagraphStyle()
// paragraphStyle.lineSpacing = 18
// imageString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: imageString.length))
//
// attributeString.insert(imageString, at: imageLocation)
// }
//
// self.shInputView.textView.attributedText = attributeString
// }
// else
// {
// // 默认文字样式
// self.shInputView.textView.typingAttributes = SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any]
// }
let
attachment
=
NSTextAttachment
.
init
()
attachment
.
image
=
image
attachment
.
bounds
=
CGRect
(
origin
:
CGPoint
.
zero
,
size
:
newSize
)
let
imageString
=
NSMutableAttributedString
(
attachment
:
attachment
)
// 设置图片文字属性
imageString
.
addAttributes
((
SHInputViewModel
.
contentAttributes
()
as?
[
NSAttributedString
.
Key
:
Any
])
!
,
range
:
NSRange
(
location
:
0
,
length
:
imageString
.
length
))
// 设置图片间距
let
paragraphStyle
=
NSMutableParagraphStyle
()
paragraphStyle
.
lineSpacing
=
18
imageString
.
addAttribute
(
NSAttributedString
.
Key
.
paragraphStyle
,
value
:
paragraphStyle
,
range
:
NSRange
(
location
:
0
,
length
:
imageString
.
length
))
attributeString
.
insert
(
imageString
,
at
:
imageLocation
)
i
+=
1
}
self
.
shInputView
.
textView
.
attributedText
=
attributeString
}
else
{
// 默认文字样式
// 默认文字样式
self
.
shInputView
.
textView
.
typingAttributes
=
SHInputViewModel
.
titleAttributes
()
as!
[
NSAttributedString
.
Key
:
Any
]
self
.
shInputView
.
textView
.
typingAttributes
=
SHInputViewModel
.
titleAttributes
()
as!
[
NSAttributedString
.
Key
:
Any
]
}
}
}
// MARK: 设置控件位置
// MARK: 设置控件位置
func
setUpSubviewsLocation
()
func
setUpSubviewsLocation
()
...
...
ShorthandMaster/Input/ViewModel/SHInputViewModel.swift
View file @
dae5e19a
...
@@ -96,9 +96,9 @@ class SHInputViewModel: NSObject {
...
@@ -96,9 +96,9 @@ class SHInputViewModel: NSObject {
let
imageData
:
Data
=
(
imageAttachment
.
image
?
.
jpegData
(
compressionQuality
:
1.0
))
!
let
imageData
:
Data
=
(
imageAttachment
.
image
?
.
jpegData
(
compressionQuality
:
1.0
))
!
// 保存的本地路径
// 保存的本地路径
let
imagePath
=
filePath
+
"/"
+
"image.jpeg"
+
imagesPathArray
.
count
.
string
let
imagePath
=
"/"
+
subFile
+
time
+
"/"
+
"image.jpeg"
+
imagesPathArray
.
count
.
string
let
imageUrl
:
URL
=
URL
(
fileURLWithPath
:
imagePath
)
let
imageUrl
:
URL
=
URL
(
fileURLWithPath
:
DocumentPath
+
imagePath
)
var
saveSucceed
:
Bool
=
Bool
(
true
)
var
saveSucceed
:
Bool
=
Bool
(
true
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment