Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
8e864f81
Commit
8e864f81
authored
Apr 12, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// 搜索
parent
29e12ba0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
13 deletions
+29
-13
YHSearchInfomationVC.swift
...axy/Classes/Modules/Home(首页)/C/YHSearchInfomationVC.swift
+1
-0
YHSearchInfoCell.swift
.../galaxy/Classes/Modules/Home(首页)/V/YHSearchInfoCell.swift
+27
-12
YHHomePageViewModel.swift
...axy/Classes/Modules/Home(首页)/VM/YHHomePageViewModel.swift
+1
-1
No files found.
galaxy/galaxy/Classes/Modules/Home(首页)/C/YHSearchInfomationVC.swift
View file @
8e864f81
...
...
@@ -233,6 +233,7 @@ extension YHSearchInfomationVC: UITableViewDelegate, UITableViewDataSource {
if
0
<=
indexPath
.
section
&&
indexPath
.
section
<
items
.
count
{
let
item
=
items
[
indexPath
.
section
]
cell
.
updateModel
(
item
)
cell
.
renderHighLightText
(
self
.
searchBar
.
textField
.
text
??
""
)
}
return
cell
}
...
...
galaxy/galaxy/Classes/Modules/Home(首页)/V/YHSearchInfoCell.swift
View file @
8e864f81
...
...
@@ -12,7 +12,7 @@ import Kingfisher
class
YHSearchInfoCell
:
UITableViewCell
{
static
let
cellReuseIdentifier
=
"YHSearchInfoCell"
var
model
:
YHHomeListModel
=
YHHomeListModel
()
override
init
(
style
:
UITableViewCell
.
CellStyle
,
reuseIdentifier
:
String
?)
{
super
.
init
(
style
:
style
,
reuseIdentifier
:
reuseIdentifier
)
setupUI
()
...
...
@@ -48,6 +48,7 @@ class YHSearchInfoCell: UITableViewCell {
}()
func
updateModel
(
_
model
:
YHHomeListModel
)
{
self
.
model
=
model
titleLabel
.
text
=
model
.
title
videoPlayImgView
.
isHidden
=
(
model
.
type
!=
1
)
if
let
url
=
URL
(
string
:
model
.
img_url
)
{
...
...
@@ -80,24 +81,38 @@ class YHSearchInfoCell: UITableViewCell {
}
}
func
highlightText
(
in
text
:
String
,
highlightString
:
String
,
highlightColor
:
UIColor
)
->
NSAttributedString
{
let
attributedString
=
NSMutableAttributedString
(
string
:
text
)
func
renderHighLightText
(
_
text
:
String
)
{
var
attributedString
=
NSMutableAttributedString
(
string
:
self
.
model
.
title
,
attributes
:
[
.
foregroundColor
:
UIColor
(
hex
:
0x121A26
)
])
if
isEmptyString
(
text
)
{
self
.
titleLabel
.
attributedText
=
attributedString
return
}
//
创建一个属性字典,用于
设置高亮样式
// 设置高亮样式
let
highlightAttributes
:
[
NSAttributedString
.
Key
:
Any
]
=
[
.
backgroundColor
:
highlightColor
.
foregroundColor
:
UIColor
(
hex
:
0x3570DC
)
]
// 查找并应用高亮样式到指定文字
let
range
=
(
text
as
NSString
)
.
range
(
of
:
highlightString
)
attributedString
.
addAttributes
(
highlightAttributes
,
range
:
range
)
return
attributedString
let
ranges
=
findOccurrencesOfString
(
text
,
inString
:
self
.
model
.
title
)
for
range
in
ranges
{
let
changeRange
=
NSRange
(
range
,
in
:
self
.
model
.
title
)
attributedString
.
addAttributes
(
highlightAttributes
,
range
:
changeRange
)
}
self
.
titleLabel
.
attributedText
=
attributedString
}
func
hopeless
()
{
func
findOccurrencesOfString
(
_
searchString
:
String
,
inString
string
:
String
)
->
[
Range
<
String
.
Index
>
]
{
var
occurrences
:
[
Range
<
String
.
Index
>
]
=
[]
var
searchStartIndex
=
string
.
startIndex
while
let
range
=
string
.
range
(
of
:
searchString
,
options
:
[],
range
:
searchStartIndex
..<
string
.
endIndex
)
{
occurrences
.
append
(
range
)
searchStartIndex
=
range
.
upperBound
}
return
occurrences
}
}
galaxy/galaxy/Classes/Modules/Home(首页)/VM/YHHomePageViewModel.swift
View file @
8e864f81
...
...
@@ -207,7 +207,7 @@ extension YHHomePageViewModel {
"page_size"
:
10
,
"title"
:
title
]
let
strUrl
=
YHBaseUrlManager
.
shared
.
curURL
()
+
YHAllApiName
.
Common
.
article
let
_
=
YHNetRequest
.
getRequest
(
url
:
strUrl
)
{
[
weak
self
]
json
,
code
in
let
_
=
YHNetRequest
.
getRequest
(
url
:
strUrl
,
params
:
params
)
{
[
weak
self
]
json
,
code
in
guard
let
self
=
self
else
{
return
}
//1. json字符串 转 对象
if
json
.
code
==
200
{
...
...
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